-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
31 lines (25 loc) · 715 Bytes
/
Game.cpp
File metadata and controls
31 lines (25 loc) · 715 Bytes
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
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;
int main()
{
int answer; // to store the computer-generated answer
int input; // to store user input
bool win = false; // check if we have won
srand(time(0)); // set the seed
answer = rand() % 100; // answer is now a random number from 1-100
while (!win) {
cout << "Enter a number" << endl;
cin >> input;
if (input < answer) {
cout << "Too low." << endl;
} else if (input > answer) {
cout << "Too high." << endl;
} else {
cout << "YOU WIN!" << endl;
win = true;
}
}
return 0;
}