// ***************************************************************** //
//  Jeff Balsley 11/2/2001											 //
//																	 //
// ***************************************************************** //
//  Known Bugs:														 //
//																	 //
// ***************************************************************** //

#include<iostream>
using namespace std;

void makeDeposit(double *p_balance);
void makeWithdrawl(double *p_balance);
void setBalance(double *p_balance);
void printBalance(double balance);

int main()
{
	char choice;
	double balance = 0;
	double * p_balance;
	p_balance = &balance;

	// **** Loop through the bank machine program **** //
	while ((choice != 'q' ) && (choice != 'Q')){
		cout << "Welcome to Bank Machine\n";
		cout << " (d)eposit\n" << " (w)ithdrawl\n";
		cout << " (s)et starting balance\n";
		cout << " (q)uit\n";
		cout << "Enter your choice > ";

		cin >> choice;

		switch (choice){
			case 'd': 
			case 'D': makeDeposit(p_balance);
					  printBalance(balance);
					  break;

			case 'w': 
			case 'W': makeWithdrawl(p_balance);
					  printBalance(balance);
					  break;

			case 's': 
			case 'S': setBalance(p_balance);
					  printBalance(balance);
					  break;
			case 'q':
			case 'Q': break;

			default: cout << "*** That is not a choise ***\n";
		}
	}
	
	printBalance(balance);

	return 0;
}

void makeDeposit(double *p_balance)
{
	double deposit;
	cout << "Enter the amount you want to deposit > ";
	cin >> deposit;
	
	// **** Calculate new balance **** //
	*p_balance = *p_balance + deposit;

	return;
}

void makeWithdrawl(double *p_balance)
{
	double withdrawl;
	
	do{
		cout << "Enter the amount you wish to withdrawl > ";
		cin >> withdrawl;

		// **** Check to make sure the have enough money in their account **** //
		if (withdrawl > *p_balance){
			cout << "*** You don't have that much in your account!***\n";
		}
	}while (withdrawl > *p_balance);
	
	// **** Calculate new balance **** //
	*p_balance = *p_balance - withdrawl;

	return;
}

void setBalance(double *p_balance)
{
	cout << "What would you like your starting balance to be ? > ";
	cin >> *p_balance;
	return;
}

void printBalance(double balance)
{
	cout.precision(2);
	cout.setf(ios_base::fixed);
	cout << "*** Balance is $" << balance << "\n";
}
