Question
Programming Challenge: 21 - Random Number Guessing Game Enhancement C++ One way to create a pseudo-random three digit number (and we are including one- and
Programming Challenge: 21 - Random Number Guessing Game Enhancement C++
One way to create a pseudo-random three digit number (and we are including one- and two-digit numbers as well) is rand()%1000. That gives numbers from 000 to 999, which is just what we might want for a simple guessing game.
But we want to take it up a notch and have the user guess a nine-digit number. Can we just say rand()%1000000000 ?
Sadly, this doesn't work. The maximum value of an int is ten digits (it is 2,147,483,647 if you really want to know) so you have (barely) enough room in the int data type to accomplish this. However - the largest pseudorandom number that our version of C++ delivers is a mere 32,767 so our method described above of getting our game numbers will not work for larger games. You will have to think outside the box on this one to get a nine-digit pseudorandom number. Let me know in a comment how you did it. Note that you should be able to guess a "hard" number in thirty tries.
As specified, have the program tell the player how many guesses were used. A good player should always be able to find a three-digit number in ten or fewer guesses.
20. Random Number Guessing Game Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number. 21. Random Number Guessing Game Enhancement Enhance the program that you wrote for Programming Challenge 20 so it keeps a count of the number of guesses the user makes. When the user correctly guesses the random number, the program should display the number of guessesStep 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