Sign in to follow this  
Pharaoh12

Dont know what to use?[solved]

Recommended Posts

Pharaoh12    100
I am trying to ask the user a math question and of he gets it wrong i want the user to be able to try again.Here is my code so far: #include <iostream> using namespace std; int main() { int answer; cout << "What is 9 X 2?"; cin >> answer; if (answer == 18) cout << "GREAT!"; else cout << "WRONG!"; cin.ignore(2); return 0; } So what can I add? [Edited by - Pharaoh12 on March 12, 2006 11:56:54 PM]

Share this post


Link to post
Share on other sites
cNoob    295
Yeh your gonna need to use a loop. I took your code and changed it so you no what to do.


#include <iostream>
using namespace std;

int main()
{
int answer;
cout << "What is 9 X 2? ";
cin >> answer;

while(answer != 9*2)
{
cout << "\nWRONG!\n";
cout << "\nTry Again ? ";
cin >> answer;
}

cout << "\nGREAT!\n";
system("pause");

return 0;
}


Great start and good luck

Share this post


Link to post
Share on other sites
Pharaoh12    100
Quote:
Original post by cNoob
Yeh your gonna need to use a loop. I took your code and changed it so you no what to do.

*** Source Snippet Removed ***
Great start and good luck


Thanks for your help and i understand what you did and thanks for showing me that system("pause"); , it works well :).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this