-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessNumber.cpp
More file actions
33 lines (31 loc) · 914 Bytes
/
Copy pathguessNumber.cpp
File metadata and controls
33 lines (31 loc) · 914 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
32
33
#include <iostream>
int main()
{
char gameStat;
unsigned short level = 1;
unsigned short numberToGuess;
unsigned short userGuess;
while (true) {
std::cout << "Woul'd like to play? [p] - play, [l]- select level, [q] - quit.\n";
std::cin >> gameStat;
if (gameStat == 'q')
break;
if (gameStat == 'l') {
unsigned short newLevel; std::cin >> newLevel;
level = newLevel * 10;
}
numberToGuess = rand() % level + 1;
for (short i = 0; i < 10; ++i) {
std::cin >> userGuess;
if (userGuess > numberToGuess)
std::cout << "Greater\n";
if (userGuess < numberToGuess)
std::cout << "Less\n";
if (userGuess == numberToGuess) {
std::cout << "You win\n";
break;
}
}
}
return 0;
}