Write a program that simulates the Monty Hall Game. Don't forget to validate user input and use functions, in addition to main() to perform major tasks.
The Monty Hall Game is named after a host of a television game show from the 70's in which a contestant could win a new car by guessing the right door that the car was behind. It became a popular puzzle because the best playing strategy in counterintuitive. Here is how the game works:
• The contestant chooses one door.
• Then Monty opens one of the other doors that does NOT have the car behind it.
• At this point in the game, the contestant has the option of changing his or her choice to the third door.
Guidelines
1. In this game you will need to generate a random number representing the door that has the car behind it. Your program must be able to generate a random integer between 1 and 3. To do this, you will need to perform the three steps below:
Step 1: You must include the following two header files at the beginning of the program in your library/header file directives.
#include <time.h>
#include <stdlib.h>
Step 2: The seed and srand must be initialized at the beginning of your main program as follows:
unsigned seed;
seed =time(NULL);
srand(seed);
Step 3: Use the following expression when you need to generate a random number from 1 to 3:
(rand() % 3) + 1;
Comments
Leave a comment