am new to c++, and am having trouble with if else statement
for this code i am writing a program that makes the computer guess a number you the user has choosen
my program works fine, but when i get in trouble is when my range gets down to zero
it will pick no new number and breakdown
so i know i need a else statement that says if the range is zero if should stop loop and it should know the number is now upperbound
and that is where i am stuck, i dnt know where i should put the statement
or exatly how it should be done
this is what i was thinking
else
range = 0
guess = upperBound
pplse help
#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;
// is devidving by zero because the range is zero so must use else statement if range equals then we know the ans
// then output the ans------where do i put it then
//if anewers is l
if (ans == 'l')
{
upperBound = guess - 1;
done = false;
cin.get();
}
// started trying to select option for h ansewer
if (ans == 'h')
{
lowerBound = guess + 1;
done = false;
cin.get();
}
//started trying if ans inputed y
if (ans == 'y')
{
cout << "yes!!!! i got it. " << endl;
done = true;
cout << "do you want to play again? (y/n)" << endl;
cin >> ans;
if (ans == 'n')
{
done = true;
}
if ( ans == 'y')
{
done = false;
}
}
}while (!done);
cin.get();
return 0;
}