The Monty Hall Problem

I'm writing a code based on the Monty Hall problem. For those of you not familiar with it, you are on a game show and must pick 1 of 3 doors to see if you won the grand prize. However, after making your initial decision, the host reveals one of the incorrect doors (or remaining incorrect door if you have picked the other incorrect door). He then gives you the option to switch your decision to the other unopened door. The program simulates this scenario 10,000 times.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
	int games = 0;
	int stayWins = 0;
	int switchWins = 0;
	int chosenDoor;
	int remainingDoor;
	int revealedDoor;
	int winningDoor;
	int option;

	srand (time(NULL));
	chosenDoor = rand() % 3 + 1;
	winningDoor = rand() % 3 + 1;

	do
	{
		do
		{
			revealedDoor = rand() % 3 + 1;
		} while (revealedDoor == chosenDoor || revealedDoor == winningDoor);

		do
		{
			remainingDoor = rand() % 3+1;
		} while (remainingDoor == chosenDoor || remainingDoor == revealedDoor);

		option = rand() % 2 + 1;
		if (option == 1)
		{
			if (chosenDoor == winningDoor)
			{
				stayWins++;
			}
		}
		if (option == 2)
		{
			chosenDoor = remainingDoor;
			if (chosenDoor == winningDoor)
			{
			        switchWins++;
			}
		}
		games++;
	} while (games < 10000);

	cout << "Out of 10,000 games, the contestant won " << stayWins << " times by staying with his/her original choice and won " << switchWins << " times by switching his/her choice.\n";
	
	return 0;
}


Option 1 is when the contestant chooses to stay with his original choice. Option 2 is when the contestant switches doors. According to the Monty Hall solution, Option 1 should win 1/3 of the time and Option 2 should win 2/3 of the time. However, when I run this program, it seems that he wins 50% of the time, regardless of which option he chooses. Is there an error in my logic or code?
Option 2 should win 50% of the time. What makes you think the odds would be higher?
Move lines 17 and 18 inside the loop at line 21.

Otherwise exactly the same game is played each time.
Topic archived. No new replies allowed.