Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <ctime>
  4.  
  5. int iterations = 100000;
  6. int win = 0;
  7. int lose = 0;
  8. int openedDoor = 0;
  9.  
  10. void main()
  11. {
  12.     srand(time(0));
  13.     int winDoor[3];
  14.     int choose = 0;
  15.     for (int i = 0; i < iterations; i++)
  16.     {
  17.         for (int i = 0; i < 3; i++)
  18.         {
  19.             winDoor[i] = 0;
  20.         }
  21.         winDoor[rand() % 3] = 1;
  22.         choose = rand() % 3;
  23.  
  24.         while (1)
  25.         {
  26.             int j = rand() % 3;
  27.             if ((winDoor[j] != 1)&&(j!=choose))
  28.             {
  29.                 openedDoor = j;
  30.                 break;
  31.             }
  32.         }
  33.         if (winDoor[choose] == 1)
  34.         {
  35.             win++;
  36.         }
  37.         else
  38.         {
  39.             lose++;
  40.         }
  41.     }
  42.     printf_s("%d\n", win);
  43.     printf_s("%d\n", lose);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement