I have to write a code that has a user guess the random number generated. Then it is suppose to ask them if they want to play again. If they say no the program ends, if they say yes the program picks another random number. I am having a problem with getting the program to continue when the user picks yes.
I am assuming I have done the loop wrong.
The program operates and does what it is suppose to up until the do you want to play again part.
#include <iostream>
#include <stdlib.h>
#include <time.h>
usingnamespace std;
/**
* DESCRIBE_THE_PROGRAM_HERE
*
* @creator YOUR_NAME_GOES_HERE
*/
int main(int, char**) {
srand(time(NULL));
constint MIN_NUMBER = 1;
constint MAX_NUMBER = 100;
constint EXIT_VALUE = -1;
constint MAX_GAMES = 256;
int random_number = rand() % MAX_NUMBER + 1;
int guess_taken = 0 ;
int n ;
char c ;
while (guess_taken < 256 )
{
cout << "Guess a number between 1 and 100 ( -1 to give up): " << endl ;
cin >> n ;
guess_taken = guess_taken + 1 ;
if (n == -1){
cout << "***QUITTER***" << endl ;
(void) system("pause");
return 0; }
if ( n > MAX_NUMBER || n < MIN_NUMBER && n != EXIT_VALUE)
cout << "Your guess is not between 1 and 100. Try again." << endl ;
if (n < random_number){
cout << "Your guess is too low." << endl ; }
if (n > random_number){
cout << "Your guess is too high." << endl ; }
if ( n == random_number){
break;}
if ( n == random_number)
cout << "*** GOT IT *** it took you " <<guess_taken<< " guesses." << endl ;
}
cout <<"Do you want to play again (Y or N)?" << endl ;
cin >> c ;
if ( c == 'N' || c == 'n'){
cout << "***Good Bye***" << endl ;
(void) system("pause");
return 0; }
if ( c == 'Y' || c =='y') {
(THIS IS WHERE I NEED HELP)}
}
(void) system("pause");
return EXIT_SUCCESS;
}