Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <ctime>
  4.  
  5. int iterations = 1000;
  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 choose1 = 0;
  15.     int choose2 = 0;
  16.     for (int i = 0; i < iterations; i++)
  17.     {
  18.         for (int i = 0; i < 3; i++)
  19.         {
  20.             winDoor[i] = 0;
  21.         }
  22.         winDoor[rand() % 3] = 1;
  23.         choose1 = rand() % 3;
  24.  
  25.         while (1)
  26.         {
  27.             int j = rand() % 3;
  28.             if ((winDoor[j] != 1)&&(j!=choose1))
  29.             {
  30.                 openedDoor = j;
  31.                 break;
  32.             }
  33.         }
  34.         while (1)
  35.         {
  36.             choose2 = rand() % 3;
  37.             if ((choose2!=choose1)&&(choose2!=openedDoor))
  38.             {
  39.                 break;
  40.             }
  41.         }
  42.         if (winDoor[choose2] == 1)
  43.         {
  44.             win++;
  45.         }
  46.         else
  47.         {
  48.             lose++;
  49.         }
  50.     }
  51.     printf_s("%d\n", win);
  52.     printf_s("%d\n", lose);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement