siriusly (5) I've made the code and all i need to do is have it restart after inputting y. The problem is that inputting y will stop the program instead of restarting. Any help is appreciated.
#include <iostream> using namespace std; int main() { int input, a; cout << "\tTriangles"; cout << "\n\t=============="; cout << "\nInput N: "; cin >> input; do { if (input %2 == 0 && input > 0) { for( int i = input; i >= 1; i-- ) { for( int j = 1; j <= input; j++) { cout << (j <= i ? "*" : " " ); } cout << endl; } } if (input %2 == 1 && input > 0 ) { for( int i = 1; i <= input; i++ ) { for( int j = 1; j <= input; j++) { cout << (j <= i ? "*" : " " ); } cout << endl; }} if (input < 1) { cout << "Input needs to be more than 1";} cout << "Restart (Y/N)?"; cin >> a; } while( a == 'y'); }
VanTate (9) well i'm pretty new to programming so take my comments with a grain of salt. couple things. maybe add some comments to your program so it is more clear to someone else what it is you are trying to accomplish. also, your cout statements in lines 9-11 were confusing to me as a user when i ran this program, but then again i don't know what this program is for so maybe it is exactly how you want it worded. i changed your int variable a to char variable ans (easier to read) and put the code you want executed in a while loop. the code below works for me and continues to loop if the user enters either y or Y. let me know if it works for you or not. cool program though, good work :)