440,686 Members | 1,558 Online
Need help? Post your question and get tips & solutions from a community of 440,686 IT Pros & Developers. It's quick & easy.

4 Replies

 P: 16 OK i understand. But now, if i put the right answer, it says WRONG!. Even after i put num1 and num2. Expand|Select|Wrap|Line Numbers int calcRealAnswer(){ if (choice==1){ int realAnswer; int num1, num2; realAnswer = num1 + num2;   if (userAnswer == realAnswer){ cout << "Correct!"; }   else { cout << "Wrong!";} } }   Jan 15 '07 #3

 P: 16 My bad, there were 2 equal signs :) BUT is there a way i can make it so that after 3 guesses, it disables the user from entering anything else and it displays the real answer? Jan 15 '07 #4

 Expert 2.5K+ P: 3,652 OK i understand. But now, if i put the right answer, it says WRONG!. Even after i put num1 and num2. Expand|Select|Wrap|Line Numbers int calcRealAnswer(){ if (choice==1){ int realAnswer; int num1, num2; realAnswer = num1 + num2;   if (userAnswer == realAnswer){ cout << "Correct!"; }   else { cout << "Wrong!";} } }   In this case, you are still not initializing num1 and num2. Thus, realAnswer is going to have some garbage value, since you don't know what will be in num1 and num2. Here's what you should have (or something like this): Expand|Select|Wrap|Line Numbers void problemType() {     int num1, num2;     num1 = calculateRandomNumber();     num2 = calculateRandomNumber();     int userChoice;     // Get user choice here: 1 = Add, 2 = Subtract, 3 = Multiply       switch (userChoice) { // This is my preference, you can use an if...else ladder         case 1:             cout << num1 << " + " << num2 << " = ?" << endl;             int userGuess;             cin >> userGuess;             if (userGuess == num1 + num2) cout << "Correct!" << endl;             else cout << "Wrong!" << endl;             break;         case 2:             // Continue with subtraction, multiplication, etc.     } } Jan 15 '07 #5