forked from 0xali3n/Hactoberfest-Beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Guessing Game.cpp
59 lines (30 loc) · 897 Bytes
/
Guessing Game.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//Guessing Game!
/*On the first line, enter range.
On the second line, first guess.
On the third, second guess.
On the fourth, third guess*/
int main(){
int x , num;
int counter = 0;
srand(time(0));
cout << "Guessing game. You got 3 tries to guess the number." << endl;
cout << "Enter range (1 to x): " << endl;
cin >> x;
num = rand() % x + 1;
do {
cout << "Guess #" << counter + 1 << ": ";
cin >> x;
if(x == num){
cout << "Well done! " << x << " is the number!" << endl;
return 0;
}
cout << "So sad, "<< x << " is a wrong number." << endl;
counter ++;
}while (counter < 3);
cout << "Game over, the number is: " << num << ", better luck next time!" << endl;
return 0;
}