Question: #include #include #include using namespace std ; int main () { srand(time( 0 )) ; char choice ; int random = rand() % 101 +
#include
#include
#include
using namespace std;
int main() {
srand(time(0));
char choice;
int random = rand() % 101 + 100;
do {
cout << "Would you like to (p)play or watch the (c)computer play? ";
cin >> choice;
int guess;
if (choice == 'p') {
do {
cout << "Enter your guess between 100 and 200. ";
cin >> guess;
if (guess > random) {
cout << "Sorry, your guess is too high, try again. ";
} else if (guess < random) {
cout << "Sorry, your guess is too low, try again. ";
} else {
cout << "Congrats, you guessed the correct number, " << random << ". ";
}
} while (guess != random);
} else 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 - num);
} else if (num > random) {
cout << "Sorry, your guess is too high, try again! ";
num = rand() % (num - random);
} else {
cout << "Congrats, you guessed the correct number, " << random << ". ";
}
} while (num != random);
}
} while (choice != 'q');
return 0;
}
okay so my output wont work fir my computer generated section. Youll see when you run it, it doesnt say high at all and will go infinitly. Help would be appreciated.
sample output fir comp generated
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
