//========================================================================= #define PROGRAMMER "SOLUTIONS, NoFrills" #define PROG_CODE "soln" #define COURSE "ECE-1021" #define YEAR (2004) #define TERM "Spring" #define SECTION (0) #define ASSIGNMENT "HW #6A" #define REVISION (0) #define TITLE "The Monty Hall Problem" #define SUBTITLE "Problem 5.20" #define EMAIL "wbahn@eas.uccs.edu" #define FILENAME "06a0soln.txt" //========================================================================= // PROBLEM: // // Write a program that simulates the Monty Hall game to answer the // question of the best strategy for playing the game. // // SOLUTION: // // The main part is to write a function that plays the game according to // the rules of the the game. So the first step is to clearly detail the // rules of the game. // // The Rules of the Game: // // Step 1: Randomly place a car behind one of three doors. // Step 2: The player picks a door. // Step 3: One of the non-picked, non-winning doors is opened. // Step 4: The player has the choice to switch doors. // Step 5: The player's final selection is revealed. // // Per the statement of the problem, the program is to play the game // according to one of three user-selected strategies. // // Strategy 1: Always stay with the door initially picked. // Strategy 1: Randomly choose whether to stay or switch. // Strategy 3: Always switch to the unpicked, unopened door. // // Our game playing function can take that as an argument and return // a logical value indicating whether the game was won or lost. Also, // per the additional material given in the homework assignment, the // function needs to know the "verbosity level" and print out information // accordingly. // // PSEUDOCODE: // // 1) TASK: Get information from user // 1.1) GET: Number of games to play. // 1.2) GET: Strategy to use. // 1.3) GET: Verbosity level. // 2) TASK: Simulate the games // 2.1) REP: // 2.1.1) PRE: // 2.1.1.1) TASK: Initialize necessary variables. // 2.1.2) WHILE: More games to play // 2.1.2.1) TASK: Play the game based on strategy and verbosity. // 2.1.2.2) TASK: Update variables based on game outcome. // 2.1.2.3) TASK: Generate output based on verbosity. // 3) TASK: Output final results.