Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int win_changed = 0,win_unchanged = 0;
- int main()
- {
- srand (time(NULL)); //random number seed will be the current time
- unsigned long long int prize, player_choice, open_door;
- for (unsigned long long int i = 0; i < 1000000000; ++i)
- {
- prize = rand()%3 + 1;
- player_choice = rand()%3 + 1;
- if (prize==player_choice)
- {
- ++win_unchanged;
- }
- for (;;)
- {
- open_door = rand()%3 + 1;
- if (open_door != prize)
- {
- break;
- }
- }
- switch (player_choice) //to change the door
- {
- case 1: if (open_door == 2)
- {
- player_choice = 3;
- }
- else
- {
- player_choice = 2;
- }
- break;
- case 2: if (open_door == 1)
- {
- player_choice = 3;
- }
- else
- {
- player_choice = 1;
- }
- break;
- case 3: if (open_door == 2)
- {
- player_choice = 1;
- }
- else
- {
- player_choice = 2;
- }
- break;
- }
- if (prize == player_choice)
- {
- ++win_changed;
- }
- }
- cout << "Wins when changed = " << win_changed << endl;
- cout << "Wins when not changed = " << win_unchanged << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement