forked from tecky708/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_number.cpp
60 lines (52 loc) · 1.21 KB
/
random_number.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
60
#include<iostream>
#include<windows.h>
#include<bits/stdc++.h>
using namespace std;
class Guess{
int n,i,num;
public:
Guess()
{
srand(time(0));
n=1+rand()%100;
cout<<endl<<"Enter a number between 1 and 100 "<<endl;
cin>>num;
}
void number();
};
void Guess ::number(){
for (i=4;i>=0;i--)
{
if (num==n)
{
cout<<endl<<"You guess the right number. ";
break;
}
else if (i==0 &&num!=n)
{
cout<<endl<<"You lost the game. ";
}
else if (num>n)
{
cout<<"The entered number is larger."<<endl;
cout<<endl<<"You left with "<<i<<" chances. "<<endl;
cout<<"Enter : ";
cin>>num;
}
else if (num<n)
{
cout<<"The entered number is smaller."<<endl;
cout<<endl<<" You left with "<<i<<" chances. "<<endl;
cout<<"Enter : ";
cin>>num;
}
}
}
int main(){
Guess obj;
obj.number();
Sleep(3*1000);
system("pause");
return 0;
}
//instructions not given