-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessing-game.cpp
More file actions
48 lines (31 loc) · 838 Bytes
/
guessing-game.cpp
File metadata and controls
48 lines (31 loc) · 838 Bytes
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
#include <iostream>
#include <stdlib.h>
#include <ctime>
using namespace std;
int main() {
int UserGuess = 0 ;
int RandNum = 0;
int TurnCounter = 0;
srand(time(0));
RandNum =rand() % 100+1;
cout <<"Please enter your guess."<<endl;
while(TurnCounter<5){
cin >> UserGuess;
if (TurnCounter ==4 && UserGuess!=RandNum){
cout<< "You lose"<<endl;
break;
}
if(UserGuess>RandNum){
cout << "Guess lower" <<endl;
}
if (UserGuess<RandNum){
cout<< "Guess higher"<<endl;
}
if (UserGuess==RandNum){
cout<< "You win"<<endl;
break;
}
TurnCounter ++;
}
return 0;
}