Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

xpand I need help with this program, can someone show me step by step how to do it. l need to expand ethe range to

image text in transcribedxpand I need help with this program, can someone show me step by step how to do it. l need to expand ethe range to be 1 to 20 and allow the user to get a maximum of 5 attempts to guess it. The game ends when the user has guessed the correct number (a win) or the number of incorrect guesses has reached 5 (a loss). At the end of each game, users should be told whether they won or lost. To make the game more interesting, the program should vary the wording of the messages that it outputs for winning, for losing, and for asking for another game. Create at least 2 different messages for each of these cases, and use random numbers to choose among them.

After printing out the win/loss messages, ask the user whether they want to play again and have them answer 'y' or 'n'. When the user quits with the 'n' answer, the program should output the total number of wins and losses. If they answer 'y', then a new random number should be generated and they will of course, have 5 attempts again to guess the number.

Here's some pseudo code that describes the outerloop of game control.

set answer to 'y'

while the answer is 'y' do the following steps

generate the random number

keep asking for a guess and comparing the guess to the computer's number until they win or have exceeded 5 guesses

print different messages out depending on whether they've won or lost

ask if they want to continue and set the response to the variable "answer"

They don't want to continue so print out the win/loss statistics

#include #include #include using namespace std; int main () int x; srand (time (NULL)) int y rand() % 20 +1; // this code will generate our random number //cout x; if (x= y) { cout

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions