Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctime>
- #include <Windows.h>
- #include <vector>
- #include <string>
- using namespace std;
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) // чтобы консоль не вылезала
- {
- srand(time(0));
- while (true)
- {
- MessageBox(0, L"Загадайте число от 1 до 100",
- L"Угадайка", MB_OK | MB_ICONINFORMATION);
- vector<int> numbers(100);
- for (size_t i = 0; i < numbers.size(); i++)
- {
- numbers[i] = i + 1;
- }
- int count = 0;
- while (true)
- {
- count++;
- int random = rand() % numbers.size();
- wstring line = L"Это число " + to_wstring(numbers[random]) + L"?";
- numbers.erase(numbers.begin() + random);
- int result = MessageBox(0, line.c_str(), L"Угадайка",
- MB_YESNO | MB_ICONQUESTION);
- if (result == IDYES)
- {
- line = L"Ха! Было " + to_wstring(count) + L" попыток. Ещё раз?";
- int result = MessageBox(0, line.c_str(),
- L"Угадайка", MB_RETRYCANCEL | MB_ICONINFORMATION);
- if (result == IDRETRY)
- break;
- else
- exit(0);
- }
- else if (numbers.size() == 0) // всё перебрали
- {
- line = L"Лживая мразь. Ещё раз?";
- int result = MessageBox(0, line.c_str(),
- L"Угадайка", MB_RETRYCANCEL | MB_ICONINFORMATION);
- if (result == IDRETRY)
- break;
- else
- exit(0);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment