Skip to content

Instantly share code, notes, and snippets.

@Grimitch
Created June 3, 2025 22:33
Show Gist options
  • Save Grimitch/fca206ef01136ad411df3f41b91a527c to your computer and use it in GitHub Desktop.
Save Grimitch/fca206ef01136ad411df3f41b91a527c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
int main() {
srand(time(0));
int upper_bound = rand() % 31 + 20;
vector<int> table;
for (int i = 0; i < 10; ++i) {
table.push_back(rand() % upper_bound + 1);
}
cout << "=== Гра: Відгадай число ===" << endl;
cout << "В таблиці є 10 чисел від 1 до " << upper_bound << "." << endl;
cout << "У вас є 5 спроб, щоб вгадати хоч одне з них!" << endl << endl;
int attempts = 5;
bool guessed = false;
int min_val = *min_element(table.begin(), table.end());
int max_val = *max_element(table.begin(), table.end());
for (int i = 1; i <= attempts; ++i) {
int guess;
cout << "Спроба " << i << ": Введіть число: ";
cin >> guess;
if (find(table.begin(), table.end(), guess) != table.end()) {
cout << " Вітаємо! Ви вгадали число: " << guess << endl;
guessed = true;
break;
} else {
cout << " Невірно. ";
if (guess < min_val) {
cout << "Ваше число менше найменшого з таблиці." << endl;
} else if (guess > max_val) {
cout << "Ваше число більше найбільшого з таблиці." << endl;
} else {
cout << "Ваше число всередині діапазону, але не в таблиці." << endl;
}
}
}
if (!guessed) {
cout << "\n Ви вичерпали всі спроби. Числа в таблиці були:\n";
for (int num : table) {
cout << num << " ";
}
cout << endl;
}
}
сделал на C++ так как знаю его лучше чем pythone, там что бы слова были показаны нужно написать пару команд но я не особо помню какие именно
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment