-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathGuess_Game_using_randomNumber.cpp
More file actions
58 lines (44 loc) · 1.1 KB
/
Copy pathGuess_Game_using_randomNumber.cpp
File metadata and controls
58 lines (44 loc) · 1.1 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
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main(void)
{
cout<<"*************************** WELCOME TO MY GAME ***********************\n";
srand((unsigned)time(NULL));
int mynum;
mynum=1+(rand()%100);
cout<<"\n GUESS MY NUMBER (1-100): ";
int num=0;
do{
cin>>num;
if(mynum==num)
{
cout<<"\n Congratulation......Correct Guess!!!!! ";
break;
}
else if(mynum<num)
{
cout<<"\n Your number is larger than my number ";
}
else
{
cout<<"\n Your number is smaller than my number ";
}
cout<<"\n try again ";
}while(num>=0);
cout<<"\n My number was : "<<mynum;
return 0;
}
/* OUTPUT
*************************** WELCOME TO MY GAME ***********************
GUESS MY NUMBER (1-100): 50
Your number is larger than my number
try again 40
Your number is larger than my number
try again 30
Your number is smaller than my number
try again 35
Congratulation......Correct Guess!!!!!
My number was : 35
*/