-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminiproject1.cpp
47 lines (43 loc) · 1.09 KB
/
miniproject1.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
#include <bits/stdc++.h>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0)));
// srand is a random functin, time(0) is a that time
// int number= 1+rand()%100;
// cout<<number;
int min = 0;
int max = 50;
int num = min + rand() % (max - min);
int lives = 5;
cout << "wELCOME TO NUMBER GUESSING GAME" << endl;
cout << "chose a number between 0 to 50" << endl;
while (lives--)
{
int choice;
cout << "enter your choice" << endl;
cin >> choice;
if (choice == num)
{
cout << "YOU WON THE GAME!!" << endl;
exit(0);
}
else if (choice < num)
{
cout << "TOO LOW! Guess High" << endl;
}
else
{
cout << "TOO HIGH! Guess Low" << endl;
}
if (lives == 0)
{
cout << "YOU LOST!" << endl;
break;
}
else{
cout<<"you have"<<lives<<"left"<<endl;
}
}
return 0;
}