Question
Write a program with C++ that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it
Write a program with C++ 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
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.
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
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