Question: you are asked to write a C++ program using array that lets the user or the computer play a guessing game. The computer randomly picks

you are asked to write a C++ program using array that lets the user or the computer play a guessing game. The computer randomly picks a number in between 1 and 100, and then for each guess the user or computer makes, the computer informs the user whether the guess was too high or too low. The program should start a new guessing game when the correct number is selected to end this run (see the sample run below). the computer part will use a binary search algorithm. leave comments next to code to clarify what they are doing.

Check this example and see how to use functions srand(), time() and rand() to generate the random number by computer.

Example of generating and using random numbers:

 you are asked to write a C++ program using array that

Here is a sample run of the program: Would you like to (p)lay or watch the (c)omputer play? p Enter your guess in between 1 and 100. 45 Sorry, your guess is too low, try again. Enter your guess in between 1 and 100. 58 Sorry, your guess is too low, try again. Enter your guess in between 1 and 100. 78 Sorry, your guess is too high, try again. Enter your guess in between 1 and 100. 67 Sorry, your guess is too low, try again. Enter your guess in between 1 and 100. 70 Sorry, your guess is too high, try again. Enter your guess in between 1 and 100. 68 Sorry, your guess is too low, try again. Enter your guess in between 1 and 100. 69 Congrats, you guessed the correct number, 69. Would you like to (p)lay or watch the (c)omputer play or (q)uit? c The computer's guess is 50. Sorry, your guess is too high, try again. The computer's guess is 25. Sorry, your guess is too high, try again. The computer's guess is 13. Sorry, your guess is too low, try again. The computer's guess is 19. Sorry, your guess is too high, try again. The computer's guess is 16. Sorry, your guess is too low, try again. The computer's guess is 17. Congrats, you guessed the correct number, 17. Would you like to (p)lay or watch the (c)omputer play or (q)uit? q Press any key to continue

Example of generating and using random numbers: #include // srand and rand functions #include // time function using namespace std; int main() const int C 10; int x; srand(unsigned(time (NULL))); // set different seeds to make sure each run of this program will generate different random numbers x- ( rand () % C); cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!