Question: why wont my computer played guessing game siphon through numbers between 100 and 200 to guess to properly. } if (choice == 'c' ) {
} if (choice == 'c')
{
int num = rand() % 101 + 100;
do
{
cout << "The computer's guess is " << num << endl;
if (num < random)
{
cout << "Sorry, your guess is too low, try again! ";
num += rand() % random;
}
else if (num > random)
{
cout << "Sorry, your guess is too high, try again! ";
num -= rand() % random;
} else
{
cout << "Congrats, you guessed the correct number," << random << endl;
break;
}
} while (num != random);
Would you like to (p)play or watch the (c)computer play or (q)quit?
c
The computer's guess is 150
Sorry, your guess is too low, try again.
The computer's guess is 175
Sorry, your guess is too low, try again.
The computer's guess is 187
Sorry, your guess is too low, try again.
The computer's guess is 193
Sorry, your guess is too high, try again.
The computer's guess is 190
Sorry, your guess is too low, try again.
The computer's guess is 191
Sorry, your guess is too low, try again.
The computer's guess is 192
Congrats, you guessed the correct number, 192.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
