/*Run a loop 100,000 times that:
- Randomly picks a door that is the "prize door"
- Randomly picks a door that is the "first choice"
- Removes one of the doors that is both not the "prize door" nor the "first choice"
- Randomly picks one of the remaining doors as your "second choice"
- Compares the "prize door" to the "first choice" and "second choice" and saves it
*/
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
srand(time(NULL));//seed random
int const COUNTER = 100000; //set counter
int first_choice;
int second_choice;
int prize_door;
int remove_door;
int WinStayCounter;
int WinSwitchCounter;
int trials;
cout << " Number of Times Staying Was the Correct Strategy: "
<< WinStayCounter << endl;
cout << " Number of Times Switching was the Correct Strategy: "
<< WinSwitchCounter << endl;
if (WinStayCounter > WinSwitchCounter)
cout << "Therefore, the best thing to do is to Stay" << endl;
else
cout << "Therefore, the best thing to do is to Switch" << endl;
for(int t= 0; t< 1000000; ++t)
{
//intialize random prize door in for loop
int prize_door =(1 + rand()% 3);
//intialize random first choice in for loop
int first_choice =(1 + rand()% 3);
int WinStayCounter = 0; //intialize counter in for loop
int WinSwitchCounter = 0;
int remove_door = (1+rand()% 3);
//remove door
do
{
remove_door = 0;
}
while (remove_door != prize_door || remove_door != first_choice);
//randomize remove door again
do
{
remove_door == (1 + rand()% 3);
}
while (remove_door == prize_door || remove_door == first_choice);
do
{
second_choice =(1+ rand()% 3);
}
while(second_choice == remove_door || second_choice == first_choice);
do
{
++WinSwitchCounter;
}
while(second_choice == prize_door);//increment switch counter
}
return 0;
}