I cannot quit after the program went to loop and if user choose not to continue game 'n' the program keeps asking for new guess.
heres the code
#include <iostream>
#include <iomanip>
//#include <stdlib>
#include <ctime> //or <ctime>
using namespace std;
int main()
{
//local constants
const int MAX_NUM = 20;
const int MIN_NUM = 1;
const int SENTINEL = -1;
const char YES = 'y';
const char NO = 'n';
//local variables
int Guess=0;
int Num1;
int Random;
int Num_Of_Guesses =1;
char Answer;
bool Play_Again = true;
/*********************************************************/
//Title
cout << "\n";
cout << setw(46) << "Guessing Game" << endl;
cout << setw(46) << "-------------";
cout << "\n\n";
//Ask for a number
cout << setw(59) << "Guess the number (1-20) or -1 to Quit: ";
cin >> Guess;
while(Play_Again)
{
//Seed the random generator
srand(time(0));
//Create a randome number between 1 - 20
Random = rand() % MAX_NUM + 1;
if (Guess == SENTINEL)
{
system("cls");
cout << setw(59) << "Number was : " << Random;
cout << "\n\n";
system ("PAUSE");
}
//Check if input doesnt equal the guess #
while (Guess != Random && Guess !=SENTINEL)
{
//Display message when # higher
if ( Guess > Random )
{
cout << setw(43) << "Too High" << endl;
cout << setw(59) << "Guess again or -1 to Quit : ";
cin >> Guess;
Num_Of_Guesses++;
}
//Display message when # lower
if( Guess < Random )
{
cout << setw(43) << "Too Low" << endl;
cout << setw(59) << "Guess again or -1 to Quit : ";
cin >> Guess;
Num_Of_Guesses++;
}
}
//When the input equals random #
if (Guess == Random)
{
system("cls");
cout << "\n";
cout << setw(53) << "You guessed correctly!";
cout << "\n\n";
cout << setw(59) << "The Random Number Was : " << Random;
cout << "\n";
cout << setw(59) << "Number of Guesses : "
<< Num_Of_Guesses;
cout << "\n\n";
system ("PAUSE");
//Clear the screen
system("cls");
cout << "\n\n";
cout << setw(55) << "Continue Game? Enter y or n: ";
cin >> Answer;
cout << "\n";
Num_Of_Guesses = 1;
//Ask for a number
cout << setw(59) << "Guess the number (1-20) or -1 to Quit: ";
cin >> Guess;
}
//Ask if user wants to play again
if(Answer!='y')
Play_Again = false;
}
return 0;
}//end main program
help fast would be appreciated..