Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- int iterations = 1000;
- int win = 0;
- int lose = 0;
- int openedDoor = 0;
- void main()
- {
- srand(time(0));
- int winDoor[3];
- int choose1 = 0;
- int choose2 = 0;
- for (int i = 0; i < iterations; i++)
- {
- for (int i = 0; i < 3; i++)
- {
- winDoor[i] = 0;
- }
- winDoor[rand() % 3] = 1;
- choose1 = rand() % 3;
- while (1)
- {
- int j = rand() % 3;
- if ((winDoor[j] != 1)&&(j!=choose1))
- {
- openedDoor = j;
- break;
- }
- }
- while (1)
- {
- choose2 = rand() % 3;
- if ((choose2!=choose1)&&(choose2!=openedDoor))
- {
- break;
- }
- }
- if (winDoor[choose2] == 1)
- {
- win++;
- }
- else
- {
- lose++;
- }
- }
- printf_s("%d\n", win);
- printf_s("%d\n", lose);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement