/*
Input Variables
    STARTING_MONEY (100)
    BET_AMOUNT (5)
    ZERO_WIN_AMOUNT (50)
    Type of Bet (odd, even, zero, or quit)
Output Variables
    Money Remaining (starts out as STARTING_MONEY)
    Number of Wins
    Number of Losses
Processing

        * Seed the random number generator.
        * while Money Remaining > 0 and Type of Bet is not Quit
              o Prompt player for type of bet
              o if the bet is not quit:
                    + Generate a random number from 0 to 36 (inclusive)
                    + If the number is zero and the player chose Zero:
					  OR the number is odd and the player chose Odd:
                      OR the number is even and nonzero and the player chose Even:
                          # Add BET_AMOUNT to Money Remaining
                          # Add one to Number of Wins
                    + Otherwise:
                          # Subtract BET_AMOUNT from Money Remaining
                          # Add one to Number of Losses
        * Print the Money Remaining, Number of Wins, and Number of Losses.
*/

#include <iostream>
#include <cstdlib>
#include <ctime>

using std::cin;
using std::cout;
using std::endl;

int main( )
{
	// Input variables
	const int STARTING_MONEY = 100;
	const int BET_AMOUNT = 5;
	const int ZERO_WIN_AMOUNT = 50;
	const int MAX_WHEEL = 37;
	char typeOfBet = ' ';

	// Output variables
	int moneyRemaining = STARTING_MONEY;
	int numberOfWins = 0;
	int numberOfLosses = 0;

	// Processing Variable
	int wheelNumber = 0;

	srand( time( 0 ) );

	cout << "Welcome to roulette. You may bet on Even, Odd, or Zero" << endl;
	cout << "(use E, O, or Z).  Each bet is $" << BET_AMOUNT <<
		"." << endl;
	cout << "If you bet on zero and win, you win $" << ZERO_WIN_AMOUNT <<
		"." << endl;
	cout << "You can choose Q to quit the game." << endl;
	cout << "The game ends automatically if you run out of money." << endl
		<< endl;

	while (moneyRemaining > 0 && typeOfBet != 'Q')
	{
		cout << endl;
		cout << "Bet on E)ven, O)dd, Z)ero or Q)uit > ";
		cin >> typeOfBet;
		typeOfBet = toupper( typeOfBet );

		if (typeOfBet =='E' || typeOfBet == 'Z' || typeOfBet == 'O' )
		{
			wheelNumber = rand( ) % MAX_WHEEL;
			cout << "The wheel comes up " << wheelNumber << endl;
			if ((wheelNumber == 0 && typeOfBet == 'Z') ||
				(wheelNumber > 0 && wheelNumber % 2 == 0 && typeOfBet == 'E') ||
				(wheelNumber % 2 == 1 && typeOfBet == 'O' ) )
			{
				if (wheelNumber == 0)
				{
					moneyRemaining = moneyRemaining + ZERO_WIN_AMOUNT;
				}
				else
				{
					moneyRemaining = moneyRemaining + BET_AMOUNT;
				}
				cout << "You win! You now have $" << moneyRemaining <<endl;
				numberOfWins++;
			}
			else
			{
				moneyRemaining = moneyRemaining - BET_AMOUNT;
				cout << "Sorry, you lose. You now have $" << moneyRemaining
					<< endl;
				numberOfLosses++;
			}
		}
		else if (typeOfBet != 'Q')
		{
			cout << "Please enter E for Even, O for Odd, Z for Zero, or "
				<< "Q to quit." << endl;
		}
	}

	cout << "Your remaining money is $" << moneyRemaining << endl;
	cout << "Number of wins: " << numberOfWins << endl;
	cout << "Number of losses: " << numberOfLosses << endl;

	cout << "Thanks for playing. Press ENTER to quit.\n";
	system("PAUSE");
	return 0;
}

