Question: 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


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
Get step-by-step solutions from verified subject matter experts
