1#include <iostream>
2#include <cstdlib>
3#include <ctime>
4using namespace std;
5
6int main()
7{
8 int num, guess, tries = 0;
9 srand(time(0)); //seed random number generator
10 num = rand() % 100 + 1; // random number between 1 and 100
11 cout << "Guess My Number Game\n\n";
12
13 do
14 {
15 cout << "Enter a guess between 1 and 100 : ";
16 cin >> guess;
17 tries++;
18
19 if (guess > num)
20 cout << "Too high!\n\n";
21 else if (guess < num)
22 cout << "Too low!\n\n";
23 else
24 cout << "\nCorrect! You got it in " << tries << " guesses!\n";
25 } while (guess != num);
26
27 return 0;
28}
29
30
31