Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Learn How to Manage Execution cmd Drive for Results.

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

1. What might have led to the misinformation?

Answered: 1 week ago

Question

2. How will you handle the situation?

Answered: 1 week ago