Thread: Monty Hall Problem

  1. #61
    Registered User
    Join Date
    Nov 2013
    Posts
    29
    Okay i am pretty sure I have it now, thanks a lot !

  2. #62
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    You might want to move the entire game into main().
    It might make sense to move some of the individual steps into their own functions though.

    Pretty good start, but you still have some problems.
    After the player has selected a door, the program needs to determine which doors are left.
    That will be a bit more complicated than what you have now:
    Code:
        if (originaldoor==1)
        {
         openeddoor=rand() % 3;
        }
        else
        {
            openeddoor=0;
        }
    If the player chose a door without the prize, there is only one remaining empty door:

    If player chose 1 and prize is behind 2, then the empty door to be opened is 3.
    If player chose 1 and prize is behind 3, then the empty door to be opened is 2.
    If player chose 2 and prize is behind 1, then the empty door to be opened is 3.
    If player chose 2 and prize is behind 3, then the empty door to be opened is 1.
    If player chose 3 and prize is behind 1, then the empty door to be opened is 2.
    If player chose 3 and prize is behind 2, then the empty door to be opened is 1.

    In that case, you don't need to generate a random value. Also the value for the possible door
    to switch to would be known along with empty door to open. So you could assign both values
    in the code that handles that.

    If the player chose the door with the prize, there are 3 possible combinations of doors remaining:

    If player chose 1, then 2 and 3 remain.
    If player chose 2, then 1 and 3 remain.
    If player chose 3, then 1 and 2 remain.

    In this case, you need to generate a random number with only two values, 0 or 1,
    and use that value to select a door to open. And again you can assign the value
    for the possible door to switch to while handling that.

    One way you might do this (possible door to switch to not shown):

    Code:
        int remaininga, remainingb;
    
        if (originaldoor == 1)
        {   remaininga = 2;
            remainingb = 3;
        }
    
        if (originaldoor == 2)
        {   remaininga = 1;
            remainingb = 3;
        }
    
        if (originaldoor == 3)
        {   remaininga = 1;
            remainingb = 2;
        }
    
        if (rand%2 == 0)
            opendoor = remaininga;
        else
            opendoor = remainingb;
    -

  3. #63
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    Quote Originally Posted by megafiddle View Post
    You might want to move the entire game into main().
    It might make sense to move some of the individual steps into their own functions though.
    Not sure if I'm misunderstanding you or not but this program has far too few functions as it is without suggesting moving the entire game into main() ;-)

  4. #64
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    That's why I also suggested moving individual steps into functions.

    -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help with "Monty Hall" simulator program.
    By jsokol7 in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2011, 11:54 PM
  2. MONTY HALL problem
    By jackalope in forum C Programming
    Replies: 10
    Last Post: 10-28-2010, 09:43 PM
  3. Replies: 1
    Last Post: 12-18-2007, 12:39 AM
  4. Monty Python
    By Stoned_Coder in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 08-18-2001, 01:29 PM

Tags for this Thread