using System; namespace Example50 { /// /// Summary description for Class1. /// class Class1 { public static bool[] door; public static Random r = new Random(); /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { int TRIALS = 1000; door = new bool[4]; for (int j = 1; j <= 10; j++) { // Place car behind random door door[1] = door[2] = door[3] = false; int carBehindDoor = r.Next(1,4); door[carBehindDoor] = true; int win = 0; int lose = 0; // Contestant picks a door at random for (int i = 1; i <= TRIALS; i++) { if (door[r.Next(1,4)]) { win++; } else { lose++; } } Console.WriteLine("Won {0} times out of {1}; winning percentage={2}", win, TRIALS, (1.0 * win) / TRIALS); // Contestant picks a random door, Monty opens door with boot prize, // contestant switches to other door int winSwitch = 0; int loseSwitch = 0; for (int i = 1; i <= TRIALS; i++) { int selectedDoor = r.Next(1,4); switch (selectedDoor) { case 1: if (door[2]) // Monty opens door 3 selectedDoor = 2; else if (door[3]) // Monty opens door 2 selectedDoor = 3; else selectedDoor = 2; break; case 2: break; case 3: break; default: Console.WriteLine("CANNOT HAPPEN!"); break; } } } } } }