hw6_functs.h
/*
Programmer: Jennifer Leopold
Date: February 29, 2016
File: hw6_functs.h
Purpose: Function prototypes used for simulating 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.
*/
#ifndef HW6_FUNCTS_H
#define HW6_FUNCTS_H
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <unistd.h>
using namespace std;
// ******************************************************
// Constants
// ASCII value of 1st char in sequence of chars for the
// slot machine
const short SYMBOL1= 97; // 'a'
// Number of display chars on slot machine tumblers ('a'..'d')
const short NUM_DISPLAY_CHARS = 4;
// Dollar winnings/losses for various outcomes
const short LOSS_IF_NO_MATCH = 5;
const short WIN_IF_TWO_MATCH = 1;
const short WIN_IF_THREE_MATCH = 30;
const short JACKPOT = 100;
// # double JACKPOT_CHAR_INDEX chars and/or triple matches
// necessary to win jackpot
const short JACKPOT_LEVEL = 7;
// Jackpot index is the one corresponding to 'a'
// (i.e., index 0 is 'a', 1 is 'b', etc.)
const short JACKPOT_CHAR_INDEX = 0;
// # times to output bell when sounding jackpot alarm
const short NUM_BELLS = 5;
// Minimum and maximum starting bank balances
const int MIN_INIT_BANK_BALANCE = 200;
const int MAX_INIT_BANK_BALANCE = 1000;
const int INIT_BANK_BALANCE_INCR = 100;
// ******************************************************
// Function prototypes
// Display a greeting to the user.
// Preconditions: None
// Postconditions: A message has been output to the screen.
void outputGreeting();
// Display a sign-off message to the user that shows the
// final game and bank balances.
// Preconditions: None
// Postconditions: A message has been output to the screen.
void outputSignOff(const int bankBalance,
const int gameBalance);
// Calculate the initial bank balance.
// Preconditions: The random number generator has been seeded.
// Postconditions: A calculated bank balanced (that should be
// used as an initial bank balance) is returned.
int calculateInitialBankBalance();
// Display a menu of game options along with a prompt to
// enter a choice.
// Preconditions: None
// Postconditions: The game options have been output to the
// screen along with a prompt to enter a choice.
void displayMenu();
// Display the current game and bank balances.
// Preconditions: None
// Postconditions: The current game and bank balances
// have been output to the screen.
void displayBalances(const int bankBalance,
const int gameBalance);
// Prompt for and get input from the user for the amount
// they want to transfer from their bank balance to their
// game balance, and update those balances accordingly.
// Preconditions: None.
// Postconditions: If the input amount is > 0 and <=
// bankBalance, then pass-by-reference parameter bankBalance
// is decreased by the input amount and pass-by-reference
// parameter gameBalance is increased by the input amount;
// otherwise, the balances are not changed.
void transferFunds(int &bankBalance, int &gameBalance);
// Prompt for and get input from the user for the number
// of spins they want to play.
// Preconditions: None.
// Postconditions: A value > 0 is returned.
short getNumSpins();
// Determine how many of 3 tumbler values match.
// Preconditions: Parameters tumbler1, tumbler2, and tumbler3
// have the index value (0..NUM_DISPLAY_CHARS-1) that
// corresponds to a slot machine symbol.
// Postconditions: The number of tumbler values that match is
// returned.
short determineNumMatches(const short tumbler1,
const short tumbler2,
const short tumbler3);
// Determine how much the player wins based on how many of
// the 3 tumblers matched.
// Preconditions: The parameter numMatches is 0, 2, or 3.
// Postconditions: The dollar amount of winnings or losses as
// a positive number is returned.
int determineWinnings(const short numMatches);
// Given the integer value that corresponds to the ith symbol
// that can be displayed on the slot machine (i = 0..
// NUM_DISPLAY_CHARS-1), return the corresponding character
// (e.g., i = 0 is SYMBOL1).
// Preconditions: The parameter tumblerDisplayAsShort is
// 0..NUM_DISPLAY_CHARS-1.
// Postconditions: The char that corresponds to the specified
// index in the display sequence is returned.
char tumblerDisplayAsChar(const short tumblerDisplayAsShort);
// Allow the user to play the game (with multiple spins).
// Preconditions: None.
// Postconditions: Pass-by-reference parameter gameBalance is
// updated with the dollar winnings and losses from the game.
void playGame(const int bankBalance, int &gameBalance);
// Output multiple bell sounds.
// Preconditions: None
// Postconditions: A series of bell sounds has been output.
void soundTheAlarm();
// Determine the number of tumbler "double matches" to the
// JACKPOT_CHAR_INDEX.
// Preconditions: None.
// Postconditions: Return the number of tumbler "double matches"
// to the JACKPOT_CHAR_INDEX.
int numDoubleJackpotSymbolMatches(const short tumbler1,
const short tumbler2,
const short tumbler3);
#endif