Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are a contestant on a game show and have won a shot at thegrand prize. Befor

ID: 3609881 • Letter: Y

Question

You are a contestant on a game show and have won a shot at thegrand prize. Before you are three doors. $1,000,000 in cashhas randomly been placed behind one door. Behind the other twodoors are the consolation prizes of dishwasher detergent. Thegame show host asks you to select a door, and you randomly pickone. However, before revealing the prize behind your door, thegame show host reveals one of the other doors that contain aconsolation prize. At this point, the game show host asks ifyou would like to stick with your original choice or to switch tothe remaining door.

Write a function to simulate the game show problem. Yourfunction should randomly select locations for the prizes, select adoor at random chosen by the contestant, and then determine whetherthe contestant would win or lose by sticking with the originalchoice or switching to the remaining door. You may wish tocreate additional functions invoked by this function.

Next, modify your program so that it stimulates playing 10,000games. Count the number of times the contestant wins whenswitching vs. staying. If you are the contestant, what choiceshould you make to optimize your chances of winning, the cash, ordoes it matter?

Explanation / Answer

#include<iostream.h>
int game();
int remain(int,int);
int main()
{
    int i,won=0,result;
    for(i=1;i<=10000;i++)
       {result=game();
       if(result==2)
          won++;
       }
cout<<"when switching you won "<<won<<"times"<<endl;
       
system("pause");
return 0;
}
int game()
{int winningdoor,choice,door,left;

int switched=0;
winningdoor=rand()%3+1;
choice=rand()%3+1;
door=remain(winningdoor,choice);
left=remain(choice,door);
choice=rand()%2;
if(choice==0)
    {switched=1;
    door=left;
    }
if(door==winningdoor)
     return 1+switched;
    
else
     return 0;
   
}

int remain(int a,intb)
{ if(a!=1&&b!=1)
      return 1;
else
     if(a!=2&&b!=2)
        return 2;
     else
         return 3;
}