/*
Programmer: Jennifer Leopold
Date: February 29, 2016
File: hw6.cpp
Purpose: Simulate a combination slot machine + ATM machine
that has a menu allowing the user to check their
bank balance, transfer funds to the game, play the
game, or quit the game.
To compile: g++ hw6_main.cpp hw6_functs.cpp -o hw6
To execute: ./hw6
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include "hw6_functs.h"
using namespace std;
int main()
{
bool gameOver = false; // true when user wants to
// end the program
short choice; // menu choice
int bankBalance = 0; // amt available to xfer
// to game balance
int gameBalance = 0; // balance to which game
// winnings/losses
// added/deducted
bool bankBalanceChecked = false; // true when user has
// checked their balance
// upon entering game
// Greeting
outputGreeting();
// Seed the random number generator
srand(5); //srand(time(NULL));
// Initialize bank balance
bankBalance = calculateInitialBankBalance();
// Continue letting user play until s/he chooses to quit
// or user runs out of money
do
{
displayMenu();
cin >> choice;
switch (choice)
{
// Check bank balance
case 1: displayBalances(bankBalance, gameBalance);
bankBalanceChecked = true;
break;
// Transfer funds to game
case 2: if (! bankBalanceChecked)
cout << "**First check your bank balance!\n";
else transferFunds(bankBalance, gameBalance);
break;
// Play game
case 3: if (! bankBalanceChecked)
cout << "**First check your bank balance!\n";
else playGame(bankBalance, gameBalance);
break;
// Leave (cash out)
case 4: if (! bankBalanceChecked)
cout << "**First check your bank balance!\n";
else gameOver = true;
break;
// Invalid selection
default: cout << "**Invalid choice!\n";
}
// If no more funds, don't let user continue
if ((bankBalance == 0) && (gameBalance == 0))
{
cout << "You're completely out of money! You're done!\n";
gameOver = true;
}
} while (! gameOver);
// Output final balances and sign-off
outputSignOff(bankBalance, gameBalance);
return 0;
}