Question
Write a C++ program to implement the Number Guessing Game . In this game, the computer chooses a random number between 1 and 100. The
Write a C++ program to implement the Number Guessing Game. In this game, the computer chooses a random number between 1 and 100. The player tries to guess the number with 7 attempts or less. Each time the player enters a guess, the computer will display a HINT to either guess HIGHER or LOWER if they do not guess the random number. Once the player guesses the number, congratulate the player and prompt the user if they would like to play the game again. If the user does not guess the number after 7 attempts, tell the user sorry and reveal the random number to the user.
Suggested Pseudocode (You could use if you want)
Initialize variables for the random number, the guessed number, the number of attempts, and the repeat option
do
{
Set attempts equal to 0 in case player wants to play game again
Set the seed to be the number of seconds since 1970 (srand( ) )
Randomly generate a number between 1 and 100 (rand() )
Display Guess the Number Game
While the guessed number does not equal the random number AND all 7 attempts have not been used
{
Prompt the user to enter a number between 1 and 100 and retrieve the number from user
Add one to the number of attempts
if (guessed number is equal to the random number)
Display Congratulations, you guessed the (random number) in (how many attempts were used)
else if (the number of attempts is equal to 7)
Display Sorry you did not guess the number and what the (random number) was
else if (guessed number is less than the random number)
Display a Hint to Guess HIGHER
else if (guessed number is greater than the random number)
Display a Hint to Guess LOWER
Ask the player if they would like to play the game again?
}
}while the player wants to keep playing the game, go to the beginning of the loop to play again
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started