This procedure should randomly set a value 1 through 3 for d

This procedure should randomly set a value 1 through 3 for doorPlayer. C++

Write a function with prototype: void pickDoorChoices(char door1, char door2, char door3, int &doorPlayer;, int &doorMonty;) This procedure should randomly set a value 1 through 3 for doorPlayer. The value of doorMonty should be set to an integer 1-3 that obeys the constraint that Monty never picks the same door as the player and never picks the door that has the car.

Solution

//i am assuming door1=\'c\' if it contains car
bool notequalcar(int doorMonty, char door1,char door2,char door3)
{
if(door1==\'c\' && doorMonty ==1)
{
  return false;
}
else if(door2==\'c\' && doorMonty==2)
{
  return false;
}
else if(door3==\'c\' && doorMonty =3)
{
  return false;
}
else
return true;
}
void pickDoorChoices(char door1,char door2,char door3,int &doorPlayer,int &doorMonty)
{
*doorPlayer = rand()%3 +1;
int flag=1;
while(flag)
{
  *doorMonty = rand()%3 +1;
  if(*doorMonty!=doorPlayer && notequalcar(*doorMonty,door1,door2,door3))
  {
      flag=0;  
    }
}
}

This procedure should randomly set a value 1 through 3 for doorPlayer. C++ Write a function with prototype: void pickDoorChoices(char door1, char door2, char do

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site