-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessthenoGame.cpp
More file actions
133 lines (108 loc) · 3.44 KB
/
guessthenoGame.cpp
File metadata and controls
133 lines (108 loc) · 3.44 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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int num;
int guess;
int tries;
srand(time(NULL));
num = (rand() % 100) + 1;
cout<<"********* GUESS THE NUMBER GAME *********"<<endl;
cout<<"Welcome to the game\nTry to guess the number ranging from 1-100 in 7 tries "<<endl;
cout<<"----Lets start the game----"<<endl;
for(tries = 7;tries >= 1;tries--){
cout<<"Enter your Guess: ";
cin>>guess;
if(tries == 6 || tries == 4){
if(guess > num){
cout<<"Too High! Try Again...."<<endl;
}
else if(guess < num){
cout<<"Too Low! Try Again....."<<endl;
}
else{
cout<<"CORRECT!!!!"<<endl;
break;
}
cout<<"tries left: "<<tries-1<<endl;
cout<<"************************"<<endl;
}
else if(tries == 7){
if(guess > num){
cout<<"Too High!"<<endl;
}
else if(guess < num){
cout<<"Too Low!"<<endl;
}
else{
cout<<"CORRECT!!!!"<<endl;
break;
}
if(num > 50)
cout<<"Hint: The number is greater than 50"<<endl;
else
cout<<"Hint: The number is less than 50"<<endl;
cout<<"tries left: "<<tries-1<<endl;
cout<<"************************"<<endl;
}
else if(tries == 5){
if(guess > num){
cout<<"Too High!"<<endl;
}
else if(guess < num){
cout<<"Too Low!"<<endl;
}
else{
cout<<"CORRECT!!!!"<<endl;
break;
}
if(num % 2 == 0)
cout<<"Hint: The number is even"<<endl;
else
cout<<"Hint: The number is odd"<<endl;
cout<<"tries left: "<<tries-1<<endl;
cout<<"************************"<<endl;
}
else if(tries == 3 || tries == 2){
if(guess > num){
cout<<"Go Higher!";
}
else if(guess < num){
cout<<"Go Lower!";
}
else{
cout<<"CORRECT!!!!"<<endl;
break;
}
if(abs(guess - num) <= 2 ){
cout<<"Very Close!"<<endl;
}
else if(abs(guess - num) <= 5){
cout<<"Close!"<<endl;
}
else if(abs(guess - num) <= 10){
cout<<"Still Far...";
}
cout<<"tries left: "<<tries-1<<endl;
cout<<"************************"<<endl;
}
else if(tries == 1){
if(guess > num){
cout<<"Too High!"<<endl;
}
else if(guess < num){
cout<<"Too Low!"<<endl;
}
else{
cout<<"CORRECT!!!!"<<endl;
break;
}
cout<<"YOU LOST"<<endl;
cout<<"tries left: "<<tries-1<<endl;
cout<<"************************"<<endl;
}
}
cout<<"-----Game Over-----";
return 0;
}