Question: C++ : Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If
C++ : Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the users guess is higher than the random number, the program should display Too high, try again. If the users guess is lower than the random number, the program should display Too low, try again. The program must use a loop that repeats until the user correctly guesses the random number or has made 10 guesses. The program needs to keep track of the number of guesses the user makes. At the end the program will display one of the messages in the table below based on the number of guesses the user took. The program must validate the users guess by making sure the value entered is between 1 and 100. If the value is not between 1 and 100, the user should be told to make another guess. The invalid input should not count as one of the 10 guesses the user is allowed.
| Number of Guesses by the User | Output Message |
| Less than 5 guesses | "Either you know the secret or you got lucky!" |
| 5-7 guesses | "You're pretty good at this!" |
| 8-10 guesses | "You'll do better next time." |
| If guess 10 is not correct | "Sorry - You have taken too many guesses." |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
