forked from iamAnki/CPP-Programs-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber guessing game.cpp
More file actions
30 lines (26 loc) · 1.11 KB
/
Number guessing game.cpp
File metadata and controls
30 lines (26 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std
int
main()
{
int num, guess, tries = 0 srand(time(0))
// seed random number generator
num = rand() % 100 + 1
// random number between 1 and 100
cout
<< "Guess My Number Game\n\n"
do
{
cout << "Enter a guess between 1 and 100 : " cin >> guess
tries++
if (guess > num)
cout
<< "Too high!\n\n" else if (guess < num)
cout
<< "Too low!\n\n" else cout << "\nCorrect! You got it in " << tries << " guesses!\n"
}
while (guess != num)
return 0
}