Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <ctime>
- using namespace std;
- bool MontyHall();
- int doorEliminator(int x, int y);
- void main()
- {
- srand(time(NULL));
- int doorchoice = 0;
- int wincounter;
- int losscounter;
- for(int i=0; i<100; i++) {
- cout << "You are a contestant on a game show with a huge grand prize!" << endl;
- cout << "I'm your game show host, Monty Hall!" << endl;
- cout << "Please pick a door!" << endl;
- bool winorlose = MontyHall();
- if (winorlose)
- cout << "Congratulations! You won $1,000,000!" << endl << endl;
- else
- cout << "You lost! Better luck next time!" << endl << endl;
- }
- system("Pause");
- }
- bool MontyHall() {
- int winningdoor;
- int playerdoor;
- int revealedDoor;
- int changeDoor;
- winningdoor = rand()%3;
- playerdoor = rand()%3;
- cout << "The winning door is " << winningdoor + 1 << endl;
- cout << "You selected door number " << playerdoor + 1 << endl;
- changeDoor = rand()%2;
- revealedDoor = doorEliminator(winningdoor, playerdoor);
- cout << "The revealed door is " << revealedDoor + 1 << endl;
- cout << "Would the contestant like to change his answer?" << endl;
- if (changeDoor == 0) {
- cout << "The player has decided to change his door!" << endl;
- playerdoor = 3 - revealedDoor - playerdoor;
- cout << "The player's new door is door number " << playerdoor + 1 << endl;
- }
- else
- cout << "The player has decided not to change his door!" << endl;
- if (playerdoor = winningdoor)
- return true;
- else
- return false;
- }
- int doorEliminator(int x, int y) {
- int revealdoor;
- if (x != y) {
- revealdoor = 3 - x - y;
- }
- else
- do {
- revealdoor = rand()%3;
- }
- while (revealdoor != x && revealdoor != y);
- return revealdoor;
- }
Add Comment
Please, Sign In to add comment