Repository navigation
Expand file tree
/
Copy pathGuess A Number.cpp
More file actions
51 lines (50 loc) · 1.55 KB
/
Copy pathGuess A Number.cpp
File metadata and controls
51 lines (50 loc) · 1.55 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
#include<bits/stdc++.h>
using namespace std;
int main()
{
cout<<"GUESS THE NUMBER GAME"<<endl;
cout<<endl;
srand(time(nullptr));
cout<<"GUESS A NUMBER RANGING FROM 1 TO 100"<<endl<<endl;
int secretNumber = 1 + (rand() % 100);
int attempt=0;
int choice;
for(int i=0;i<1000;i++)
{
cout<<"Enter Your Predicted Number: ";
cin>>choice;
if(choice<0 || choice>100)
{
cout<<"Invalid Number. Please Enter A Number Ranging From 1 to 100"<<endl<<endl;
}
else
{
if (choice == secretNumber)
{
attempt++;
cout<<"---------------------------------------------------------------------------";
cout<<endl;
cout<<"Hurrah! You Have Find It."<<endl;
cout<<"The secret number is "<<secretNumber<<endl;
cout<<"---------------------------------------------------------------------------"<<endl;
cout<<"No of attempts made : "<<attempt<<endl;
break;
}
else
{
if(choice > secretNumber)
{
attempt++;
cout<<endl;
cout<<"Try with a smaller number..."<<endl<<endl;
}
else if(choice < secretNumber)
{
attempt++;
cout<<endl;
cout<<"Try with a larger number..."<<endl<<endl;
}
}
}
}
}