Write a program that generates a random number in the range of 1 through 20 and
ID: 3640464 • Letter: W
Question
Write a program that generates a random number in the range of 1 through 20 and asks the user to guess what the number is. If the user’s guess is lower than the random number, the program should display “ Too low, try again.”If the user’s guess is higher than the random number, the program should display “ Too high, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Also, it should keep a count of the number of guesses that the user makes. When the user correctly guesses the random numbers, the program should display the number of guesses.
Explanation / Answer
#include #include #include using namespace std; int main() { srand((unsigned int)time(NULL)); //Seed the random number generator //Generate the random number between 1 and 20 int random = (rand() % 20) + 1; int guess = 0, numGuess = 0; while(guess != random) { cout > guess; if(guessRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.