#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int secret = rand() % 20 + 1;
int number;
int attempts = 0;
cout << "Я загадал число от 1 до 20." << endl;
while (true) {
cout << "Введите число: ";
cin >> number;
if (number < 1 || number > 20) {
cout << "Ошибка! Введите число от 1 до 20." << endl;
continue;
}
attempts++;
if (number > secret) {
cout << "Слишком много!" << endl;
}
else if (number < secret) {
cout << "Слишком мало!" << endl;
}
else {
cout << "Вы угадали!" << endl;
cout << "Попыток: " << attempts << endl;
break; // ВОТ ЗДЕСЬ цикл прекращается
}
}
return 0;
}