-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrnd game1
37 lines (31 loc) · 840 Bytes
/
rnd game1
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
// rnd game
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
// variables
int max = 10;
// generate random number
srand(time(0));
int rnum = rand() % (max + 1);
// display instructions
cout << "Try to guess the random number between 0 and " << max << ": " << endl;
// loop until user enters the correct number
int x;
do {
// read user input
cin >> x;
// check the number entered and display guessing info
if(x > rnum){
cout << "The random number is smaller!" << endl;
} else if(x < rnum) {
cout << "The random number is bigger!" << endl;
} else {
cout << "Wow you found the random number!" << endl;
}
} while(x != rnum);
// ends program
return 0;
}