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, open_door_choice = 0;
- unsigned long long int trials;
- int main()
- {
- cout << "Enter the number of simulations you want to make : ";
- cin >> trials;
- if (trials == 0)
- {
- trials = 10000000000;
- }
- 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 < trials; ++i)
- {
- prize = rand()%3 + 1;
- player_choice = rand()%3 + 1;
- if (prize==player_choice)
- {
- ++win_unchanged;
- }
- //to open a door
- if (prize != player_choice)
- {
- for (int i = 1; i < 4; ++i)
- {
- if (i != prize && i != player_choice)
- {
- open_door = i;
- break;
- }
- }
- }
- else
- {
- if (open_door_choice == 0)
- {
- for (int i = 1; i < 4; ++i)
- {
- if (i != prize)
- {
- open_door = i;
- open_door_choice = 1;
- break;
- }
- }
- }
- else
- {
- for (int i = 3; i <= 1; ++i)
- {
- if (i != prize)
- {
- open_door = i;
- open_door_choice = 0;
- 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