Write a C++ program with the following 2 functions that plays the game of “guess the number” as follows: Function 1: Generate the random number. Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. Main: I have a number between 1 and 1000. Can you guess my number? Please type in your first guess. Function 2: The user guesses. The program then displays the following: The player then types a first guess. The program then responds with one of the following: 1. Excellent! You guessed the number! Otherwise a. If the number of guesses is 10 or fewer, print “Either you know the secret or you got lucky!” b. If the player guesses the number in 10 tries, then print “Ahah! You know the secret!” c. If the player makes more than 10 guesses, then print, “You should be able to do better!” If the player failed to guess the number: 1. Too low. Try again. Or 2. Too high. Try again. Followed by: Would you like to play again (y or n)? If the player’s guess is incorrect, you program should loop until the player finally gets the number right. Your program should keep telling the player Too high or Too low to help the player “zero in” on the correct answer. You must count the number of guesses the player makes The loop in Main: Followed by: Would you like to play again (y or n)? Your player must play this game at least 3 times. You are not to run the program 3 times, you are to loop thru the program each time.
Write a C++ program with the following 2 functions that plays the game of “guess the number” as follows:
Function 1: Generate the random number. Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 1000.
Main:
I have a number between 1 and 1000.
Can you guess my number?
Please type in your first guess.
Function 2: The user guesses.
The program then displays the following:
The player then types a first guess. The program then responds with one of the following:
1. Excellent! You guessed the number!
Otherwise
a. If the number of guesses is 10 or fewer, print “Either you know the secret or you got lucky!”
b. If the player guesses the number in 10 tries, then print “Ahah! You know the secret!”
c. If the player makes more than 10 guesses, then print, “You should be able to do better!”
If the player failed to guess the number:
1. Too low. Try again.
Or
2. Too high. Try again.
Followed by: Would you like to play again (y or n)?
If the player’s guess is incorrect, you program should loop until the player finally gets the number right. Your program should keep telling the player Too high or Too low to help the player “zero in” on the correct answer. You must count the number of guesses the player makes
The loop in Main:
Followed by: Would you like to play again (y or n)?
Your player must play this game at least 3 times. You are not to run the program 3 times, you are to loop thru the program each time.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps