Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it tells the

image text in transcribed
image text in transcribed
image text in transcribed
Write a program that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it tells the user how many divisors it has, (excluding 1 and the number itself). Each time the user makes a wrong guess, it displays "Wrong" and says if the guess was too low or too high, until the user gets it right, in which case it says "Right" and says how many trials it took to guess it. Then, the program asks the user if he or she wants to continue. If the answer is 'y' or 'Y', it generates another number between 1 and 50 and repeats the game. If not, it prints the average of all trials with one decimal place and ends. Example: I've picked a number between 1 and 50 that has 0 divisor(s). Guess the number: 23 Too low! Guess the number: 37 Too low! Guess the number: 43 Too high! Guess the number: 41 Too high! Guess the number: 41 Right! It took you 4 trials. Play again? [y/N]: y I've picked a number between 1 and 50 that has 1 divisor(s). Guess the number: 25 Too low! Guess the number: 49 Right! It took you 2 trials. Play again? [y/N]: y I've picked a number between 1 and 50 that has 3 divisor(s). Guess the number: 30 Too high! Guess the number: 24 Right! It took you 2 trials. Guess the number: 25 Too low! Guess the number: 49 Right! It took you 2 trials. Play again? [y]: y I've picked a number between 1 and 50 that has 3 divisor(s). Guess the number: 30 Too high! Guess the number: 24 Right! It took you 2 trials. Play again? [y/N]: n You averaged 2.7 trials in 3 games. Press any key to continue. Submit only the cpp file

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

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago