Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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, tries=0;

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() % 101 + 100;

num++;

}

if (num < random)

{

cout << "Sorry, your guess is too high, try again!";

num = rand() % 101 + 100;

num--;

}

}while (num != random);

}

}while (choice != 'q');

return 0;

}

Would you like to (p)play or watch the (c)computer play?

p

Enter your guess between 100 and 200.

150

Sorry, your guess is too low, try again.

Enter your guess between 100 and 200.

175

Sorry, your guess is too low, try again.

Enter your guess between 100 and 200.

188

Sorry, your guess is too high, try again.

Enter your guess between 100 and 200.

181

Congrats, you guessed the correct number, 181.

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.

Would you like to (p)play or watch the (c)computer play or (q)quit?

q

why wont my computer output do this. anything will help. It keeps putting out the same number

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Compare levels of resolution in conflict outcomes?

Answered: 1 week ago

Question

Strategies for Managing Conflict Conflict Outcomes?

Answered: 1 week ago