-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.cpp
More file actions
39 lines (31 loc) · 1.15 KB
/
3.cpp
File metadata and controls
39 lines (31 loc) · 1.15 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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const int MIN_NUMBER = 1;
const int MAX_NUMBER = 100;
int main() {
int secretNumber = rand() % (MAX_NUMBER - MIN_NUMBER + 1) + MIN_NUMBER;
int userinput;
int attempts = 0;
cout << "Я загадал число от " << MIN_NUMBER << " до " << MAX_NUMBER << "." << endl;
do {
cout << "Введите ваше число: ";
cin >> userinput;
attempts++;
if (userinput < MIN_NUMBER || userinput > MAX_NUMBER) {
cout << "Число должно быть в диапазоне от " << MIN_NUMBER
<< " до " << MAX_NUMBER << "!" << endl;
continue;
}
if (userinput > secretNumber) {
cout << "Перелет!" << endl;
} else if (userinput < secretNumber) {
cout << "Недолет!" << endl;
} else {
cout << endl << "Поздравляю! Вы угадали число " << secretNumber
<< " за " << attempts << " попыток!" << endl;
}
} while (userinput != secretNumber);
return 0;
}