BeloMaximka

Belov_HW_S2

Nov 1st, 2021 (edited)
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <ctime>
  2. #include <Windows.h>
  3. #include <vector>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) // чтобы консоль не вылезала
  8. {
  9.     srand(time(0));
  10.     while (true)
  11.     {
  12.         MessageBox(0, L"Загадайте число от 1 до 100",
  13.             L"Угадайка", MB_OK | MB_ICONINFORMATION);
  14.  
  15.         vector<int> numbers(100);
  16.         for (size_t i = 0; i < numbers.size(); i++)
  17.         {
  18.             numbers[i] = i + 1;
  19.         }
  20.  
  21.         int count = 0;
  22.         while (true)
  23.         {
  24.             count++;
  25.             int random = rand() % numbers.size();
  26.             wstring line = L"Это число " + to_wstring(numbers[random]) + L"?";
  27.             numbers.erase(numbers.begin() + random);
  28.  
  29.             int result = MessageBox(0, line.c_str(), L"Угадайка",
  30.                 MB_YESNO | MB_ICONQUESTION);
  31.             if (result == IDYES)
  32.             {
  33.                 line = L"Ха! Было " + to_wstring(count) + L" попыток. Ещё раз?";
  34.                 int result = MessageBox(0, line.c_str(),
  35.                     L"Угадайка", MB_RETRYCANCEL | MB_ICONINFORMATION);
  36.                 if (result == IDRETRY)
  37.                     break;
  38.                 else
  39.                     exit(0);
  40.             }
  41.             else if (numbers.size() == 0) // всё перебрали
  42.             {
  43.                 line = L"Лживая мразь. Ещё раз?";
  44.                 int result = MessageBox(0, line.c_str(),
  45.                     L"Угадайка", MB_RETRYCANCEL | MB_ICONINFORMATION);
  46.                 if (result == IDRETRY)
  47.                     break;
  48.                 else
  49.                     exit(0);
  50.             }
  51.         }
  52.     }
  53. }
Add Comment
Please, Sign In to add comment