forked from rahul22mrk/hackoctoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessNumberGame.cpp
More file actions
35 lines (34 loc) · 755 Bytes
/
GuessNumberGame.cpp
File metadata and controls
35 lines (34 loc) · 755 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
#include<bits/stdc++.h>
using namespace std;
int main(){
int minValue = 0;
int maxValue = 100;
int wrongAttempt = 0;
int resultNumber = (rand()%100 + rand()%10)%100;
int guessNumber = 0;
while(1){
cout<<"Number is b/w "<<minValue<<" and "<<maxValue;
cout<<"\n\t\t\t\t\tEnter Your Guess!!\n";
cin>>guessNumber;
if(guessNumber<=minValue || guessNumber>=maxValue){
wrongAttempt++;
continue;
}
else{
if(guessNumber == resultNumber){
cout<<"Hurreeee! You Guess it successfully.";
cout<<"WRONG ATTEMPTS - "<<wrongAttempt;
break;
}
else{
wrongAttempt++;
if(guessNumber<resultNumber){
minValue = guessNumber;
}
else if(guessNumber>resultNumber){
maxValue = guessNumber;
}
}
}
}
}