<?
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

// header() - Print out some header information containing de name of the program
void header() {
	cout << "The Monty Hall Game Show" << endl;
	cout << "========================" << endl;
}

// putCar() - Put the car behind 1 of the 3 doors randomly
int putCar() {
	return rand()%3+1;
}

// pickDoor() - Choose 1 of 3 doors where YOU think the car is behind
int pickDoor() {
	return rand()%3+1;
}

// openDoor() - Open 1 of the 2 other doors randomly
int openDoor(int yourChoice) {
	int door = yourChoice;

	while(door==yourChoice)
		door = rand()%3+1;
	
	return door;
}

// keepChoice() - Make a doorswitch or not, if 1, pick last door, if 0, keep yourChoice
int keepChoice(int yourChoice, int openedDoor) {
	if(rand()%2)
		return 6-yourChoice-openedDoor;
	else
		return yourChoice;
}

// main() - Main program
int main() {
	srand((unsigned)time(NULL));
	int percWinNC = 0, percWinCH = 0, percLost = 0;

	// print header
	header();

	for(int i=0; i<10000; i++) {
		int nmbr = rand()%3+1;
		int car = putCar();
		int choice = pickDoor();
		int door = openDoor(choice);
		int final = keepChoice(choice, door);

		if(choice==final && choice==car) percWinNC++;
		else if(choice!=final && final==car) percWinCH++;
		else percLost++;
	}

	cout << " .Probability of winning, no change: " << percWinNC/100.0 << "%" << endl;
	cout << " .Probability of winning, after change: " << percWinCH/100.0 << "%" << endl;
	cout << " .Probability of losing: " << percLost/100.0 << "%" << endl;
}