109k views
5 votes
Write a program that generates a random number between 1 and 100 and ask the user to guess what the number is. if the user's guess is higher than the random , number, the

User Dbalakirev
by
7.9k points

1 Answer

2 votes
You didn't specify a language, so here it is in C++.


#include <iostream>
#include <ctime>

int main()
{
srand(time(NULL));

int random, guess;

random = rand() % 100 + 1;
std::cout << "Random number generated!\\Guess the number: ";

std::cin >> guess;

if (guess == random)
std::cout << "Yes!";
else
std::cout << "No!";

return 0;
}
User Shashank Rawat
by
8.0k points

No related questions found