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 want. Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is too high then the program should display "Too high, try again." If the user's guess is lower than the random number the program should say "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number. The program should keep track of the number of guesses the user makes. When the user correctly guesses the random number, the program should display the number of guesses. 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. The programs needs to include a menu that allows the user to select easy (3 digit number), medium (6 digit number), or hard (9 digit number). 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.
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 want.
Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is too high then the program should display "Too high, try again." If the user's guess is lower than the random number the program should say "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number. The program should keep track of the number of guesses the user makes. When the user correctly guesses the random number, the program should display the number of guesses.
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.
The programs needs to include a menu that allows the user to select easy (3 digit number), medium (6 digit number), or hard (9 digit number). 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.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images