i made this game where the user has to guess the number that the computer chose at random. i had it working perfectly, then i wanted to make it so that the user can loop and restart the game. here is my code:
Code:
#include <iostream>
#include <ctime>
using namespace std;
int main ( )
{
srand (time (NULL) );
int Secret_Number = rand ( ) % 24 + 1;
char YES = 'y';
int Guess = 0;
float num1 = 1;
int choice = 3;
int game;
do
{
cout << "In this game, you will be guessing a random number between" << endl;
cout << "0 and 24 that the computer has chosen." << endl;
cout << "Do you want to play the game? press 'y' to play." << endl;
cin >> choice;
if(choice == YES)
{
cin >> game;
}
else
{
return 0;
}
cout << "----------------------------------------------------------" << endl;
while(game)
{
cout << "Guess the random number." << endl;
cin >> Guess;
if (Guess > Secret_Number)
{
cout << "Your guess is too high." << endl;
}
if (Guess < Secret_Number)
{
cout << "Your guess is too low." << endl;
}
if (Guess == Secret_Number)
{
cout << "Good job! You guessed the secret number!" << endl;
cout << "Thanks for playing." << endl;
}
}
cout << "Do you want to play the game? press 'y' to play." << endl;
cin >> choice;
if (choice == YES)
{
continue;
}
else
{
cout << "Thanks for playing!" << endl;
break;
}
}while (Guess != Secret_Number);
system ("PAUSE");
}
when i debug it, it just closes. help?
and thanks in advance!