Hi all, I'm new here. I was doing the C++ tutorial on the main website and, two lessons in, found the if statements.
Now I love if statements so I started messing around to see what I could do with them. I managed to get a multiple part if statement program running but I could not for the life of me find a way to get it to repeat its query and receive new input.
My code is as follows:
Now this program works, but it only works once. After entering a single value and pressing enter, it ends upon pressing enter again.
using namespace std;
int main ()
cout<<"Please multiply 5 and 10:"; // Asks for answer
cin>> a; // The input is put in answer
cin.ignore(); // Throw away enter
if ( a==50 )
cout<<"Congratulations, you can do basic arithmetic.";
else if ( a<50 )
cout<<"Seriously? You can't do that problem? You suck.\n";
else if ( 100>a && a>50 )
cout<<"Dear god man this isn't that hard!\n";
else if ( 200>a && a>100 )
cout<<"Alright now you're just intentionally ........ing me off.\n";
else if (a>=200)
cout<<"Ok, I'm done. Get out of here stalker.";
I've tried adding cout<<"Please multiply 5 and 10:"; and cin.ignore(); to the end of each if statement, I've tried looking a few lessons ahead at loops but couldn't figure out a way to adapt one to do this. While adding the above two lines achieved some of what I wanted, it still didn't accept new input.
To reiterate, what I want it to do is functionally repeat everything after int main() EXCEPT if "else if (a>=200)" is true.
Thanks in advance,