I'm not sure if everyone has heard of the monty hall scenario but I have written a program which attempts to reproduce it. I've been quite boggled with it so far and I've written this as an attempt I really need an answer by tonight if possible so any input/help would be appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int choice = rand() % 3, prize = rand() % 3, otherdoor, choice2, winstay = 0, winmove = 0, i, x;
float percentstay, percentmove;
for(x = 0; x <= 10000; x++)
{
if( choice == prize)
{
for( i= 0; i <= 3; i++)
{
if( i != prize)
{
otherdoor = i;
}
}
choice2 = (rand()%2);
if(choice2 == prize)
{
if(choice2 == choice)
{
winstay++;
}
}
}
if( choice != prize)
{
for( i = 0; i <= 3; i++)
{
if(i != prize&&choice)
{
otherdoor = i;
}
}
choice2 = (rand()%2);
if(choice2 == prize)
{
if(choice2 == prize)
{
winmove++;
}
}
}
}
percentstay = (winstay / 10000) * 100;
percentmove = (winmove / 10000) * 100;
printf("wins changing %.2f\nwins staying %.2f\n" , percentmove , percentstay);
system("pause");
return 0;
}