Hello all.
I'm currently working on this project and I have this problem that I can't figure out.
take a look at my codes and please give me some ideas. I'm kinda new to C++ by the way. thanks
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std ;
bool done = false ;
char answer ;
bool found = true ;
int range ;
int main()
{
int lowerBound = 1 ;
int upperBound = 101 ;
int range ;
int guess ;
cout << " \t\tWelcome to my guess game!\n " ;
cout << " \n\nThink of a number and I will try to guess it.\n\n." ;
do
{
range = upperBound - lowerBound ;
srand(static_cast < unsigned int >(time(0))) ;
range = upperBound - lowerBound ;
guess = lowerBound + (rand() % range) ;
cout << " Is your number: " << guess << " (l/h/y) " << endl ;
cin >> answer ;
{
if (answer == 'l' || answer == 'L')
{
cout << " lower " ;
upperBound = guess - 1 ;
done = false ;
}
if (answer == 'h' || answer == 'H')
{
cout << " higher " ;
lowerBound = guess + 1 ;
done = false ;
}
if (answer == 'y' || answer == 'Y')
{
cout << " Yes !!!! i got it. " << endl ;
cout << " Do you want to play again? (y/n) " << endl ;
cin >> answer ;
done = true ;
}
if (guess == lowerBound + 1 || guess == upperBound - 1)
{
cout << " \nHah ! I know your number is: " << upperBound << endl ;
cout << " Do you want to play again? " << endl ;
cin >> answer ;
}
if (answer == 'y'|| answer == 'Y')
{
done = false ;
}
if (answer == 'n' || answer == 'N')
{
done = true ;
}
}
} while (!done) ;
return 0 ;
}