Загрузка данных


#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
    int secret = rand() % 20 + 1;
    int number;
    int attempts = 0;

    cout << "Я загадал число от 1 до 20.\n";

    while (true) {
        cout << "Введите число: ";
        cin >> number;

        if (number < 1 || number > 20) {
            cout << "Ошибка! Введите число от 1 до 20.\n";
            continue;
        }

        attempts++;

        if (number > secret)
            cout << "Слишком много! Попробуйте ещё.\n";
        else if (number < secret)
            cout << "Слишком мало! Попробуйте ещё.\n";
        else {
            cout << "Поздравляем, вы угадали!\n";
            cout << "Попыток: " << attempts << endl;
            break;
        }
    }

    return 0;
}