You might want to move the entire game into main().
It might make sense to move some of the individual steps into their own functions though.
Pretty good start, but you still have some problems.
After the player has selected a door, the program needs to determine which doors are left.
That will be a bit more complicated than what you have now:
Code:
if (originaldoor==1)
{
openeddoor=rand() % 3;
}
else
{
openeddoor=0;
}
If the player chose a door without the prize, there is only one remaining empty door:
If player chose 1 and prize is behind 2, then the empty door to be opened is 3.
If player chose 1 and prize is behind 3, then the empty door to be opened is 2.
If player chose 2 and prize is behind 1, then the empty door to be opened is 3.
If player chose 2 and prize is behind 3, then the empty door to be opened is 1.
If player chose 3 and prize is behind 1, then the empty door to be opened is 2.
If player chose 3 and prize is behind 2, then the empty door to be opened is 1.
In that case, you don't need to generate a random value. Also the value for the possible door
to switch to would be known along with empty door to open. So you could assign both values
in the code that handles that.
If the player chose the door with the prize, there are 3 possible combinations of doors remaining:
If player chose 1, then 2 and 3 remain.
If player chose 2, then 1 and 3 remain.
If player chose 3, then 1 and 2 remain.
In this case, you need to generate a random number with only two values, 0 or 1,
and use that value to select a door to open. And again you can assign the value
for the possible door to switch to while handling that.
One way you might do this (possible door to switch to not shown):
Code:
int remaininga, remainingb;
if (originaldoor == 1)
{ remaininga = 2;
remainingb = 3;
}
if (originaldoor == 2)
{ remaininga = 1;
remainingb = 3;
}
if (originaldoor == 3)
{ remaininga = 1;
remainingb = 2;
}
if (rand%2 == 0)
opendoor = remaininga;
else
opendoor = remainingb;
-