I need help when i run the app. and enter the wrong answer "No. please try again " continues to loop forever . I want it to say it only once and repeat the same question. Any ideas? I thought maybe the braces were off somewhere but I'm not sure.
//Exercise 12.16: MultiplicationTeacher.cpp
// This game asks the user to enter the product of two
// randomly generated numbers in the range 0-9.
#include <iostream> // required to perform C++ stream I/O
#include <ctime> // contains prototype for function time
# include <iomanip>
// contains function prototypes for functions srand and rand
#include <cstdlib>
using namespace std; // for accessing C++ Standard Library members
// function prototypes
int generateQuestion();
void generateOutput();
// function main begins program execution
int main()
{
// randomize random number generator using current time
srand( time( 0 ) );
// define variables
int userAnswer = 0; // stores the user's answer
int correctAnswer=0; // stores the correct answer
while (userAnswer != -1 )
{
{
correctAnswer= generateQuestion ();
cin >> userAnswer;
}
while (userAnswer != correctAnswer && userAnswer != -1)
{
cout << "\nNo. Please try again ( -1 to end ) ?"<<endl;
}
if(userAnswer==correctAnswer)
{
generateOutput();
}
}
return 0; // indicates successful termination
} // end function main