beginning in c++, i have a question of a recent program
for this program i am trying to create a game where the computer try's to guess a number 1-100 that the user has chosen and i have it running good.
but where i have a problem is at the end, i want to give the user the option to play again or quit
so i have put another loop where this is done, but the problem is when user input yes i do not know how to send program back to beginning.
so it will guess again for users number is this possible, how can i fix please help me.
here is what i have
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast < unsigned int >(time(0)));
int lowerBound = 1;
int upperBound = 101;
bool done = false;
char ans;
bool found = true;
do
{
int range;
int guess;
range = upperBound - lowerBound;
guess = upperBound - (rand() % range);
cout << "Is your number? " << guess << " (l/h/y) " << endl;
cin >> ans;
if (ans == 'l')
{
upperBound = guess - 1;
done = false;
cin.get();
}
if (ans == 'h')
{
lowerBound = guess + 1;
done = false;
cin.get();
}
if (ans == 'y')
{
cout << "yes!!!! i got it. " << endl;
done = true;
}
}while (!done);
do
{
cout << "do you want to play again? (y/n)" << endl;
cin >> ans;
if (ans == 'n')
{
done = true;
}
if ( ans == 'y')// this is my problem once inputs yes i want to go back to beginning of program
{
done = false;
}
}while (!done);
cin.get();
return 0;
}