C++ 20. Random Number Guessing Game Write a program that generates a random numb
ID: 3585725 • Letter: C
Question
C++ 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 (The one i need but I need the otherone in order to do this one) Enhance the program that you wrote for Programming Challenge 20 so it keeps a count of the number of guesses that the user makes. When the user correctly guesses the random number, the program should display the number of guesses. C++!
Explanation / Answer
20)
Answer:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int RandNum,
Seed,
Guess;
Seed = time(0);
srand(Seed);
RandNum = 1 + rand() % 100;
// cout << RandNum << endl;
cout << " I generated a random number between 1 and 100 "
<< "Can you guess what my number is? ";
cin >> Guess;
while (Guess > RandNum)
{
cout << "Too high. Try again. ";
cin >> Guess;
}
while (Guess < RandNum)
{
cout << "Too low. Try again. ";
cin >> Guess;
}
cout << "Congratulations. You figured out my number. ";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.