(9) (Modified Monty Hall Problem) You are a contestant in a game show. A single
ID: 3716528 • Letter: #
Question
(9) (Modified Monty Hall Problem) You are a contestant in a game show. A single (1) prize is behind one of 4 closed Doors (A-D). .You choose a Door, call it "Door A." We do not know yet whether A is correct because all Doors remain closed The moderator must show us one of the 2 unguessed doors has no prize. (Easy because there is only 1 prize but there are 3 un- guessed Doors.) .Call "Door B" the unguessed Door that the moderator shows us has no prize. Doors C and D remain unguessed and unopened. The moderator offers us a choice: Keep our (still-closed) choice Door A or choose DoorCor D (about which we know nothing with certainty) .Explanation / Answer
#include<iostream>
# include <time.h>
using namespace std;
int irand(int limit) {
/* return a random number between 0 and limit inclusive.
*/
int divisor = RAND_MAX/(limit+1);
int retval;
do {
retval = rand() / divisor;
} while (retval > limit);
return retval;
}
int main()
{
int prize[3];
int ch;
int cs=0,cc=0,lc=0,ls=0,i=0,j=10000;
int val1,val;
srand(time(0));
while(j)
{
for(i=0;i<3;i++)
{
prize[i]=1;
}
prize[irand(2)] = 10;
for(i=0;i<3;i++)
{
if(prize[i]!=10)
prize[i]=1;
}
//cout<<"choose from prizes 1-3<<endl";
//cin>>ch;
ch = irand(2);
val = ch;
for(i=0;i<3;i++)
{
if( prize[i]==1 && val != i)
{
//cout<<"one of the consolation prize is at position "<<i+1<<endl;
break;
}
}
//cout<<"choose from rest of the prizes ";
//cin>>ch;
ch = irand(2);
while(ch==i)
ch = irand(2);
val1 = ch;
if(prize[val]==10)
{//cout<<"Congrats you have stuck to your choice and you have won $1 million";
cs++;
}
else ls++;
if(prize[val1]==10 && val1 != val)
{//cout<<"Congrats your change worked and you have won $1 million";
cc++;
}
else
lc++;
//cout<<"You have won a consolation prize";
j--;
}
cout<<"If u had stuck to your choice "<<cs<<" wins and "<<ls<<" losses "<<endl<<"else if you had changed your choice "<<cc<<" wins and "<<lc<<" losses "<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.