All pastes #751673 Raw Edit

Someone

public cpp v1 · immutable
#751673 ·published 2007-10-27 16:40 UTC
rendered paste body
/*  CPP 230 - 9/19/2007  by: Joey Burgett  Instructor:  Mark Laffoon    Chapter 3 - Project 9    Purpose:  Virtual Craps  Revision 1: 9/21/2007    + Add support for gambling*/#include <cstdlib>#include <iostream>/* Constants          GAMES_TO_PLAY = # of Games to Roll (Ignored if MODE_AUTOMATIC = true)   Revision 1:          MODE_AUTOMATIC = Automated play (true) / Manual/Gambling (false)*/const int GAMES_TO_PLAY = 10000;const bool MODE_AUTOMATIC = false;/* Enumerations:        WIN = 0; LOSE = 1; AGAIN = 2*/enum Results { WIN, LOSE, AGAIN };enum Results RollResults;/* Globals:                 iPoint = Point Value                   iWon = # of matches won                  iLost = # of matches lost          iDice1/iDice2 = DUH!             bFirstRoll = Toggle indicating first roll of a game   Revision 1:               dBalance = Bank Amount              dBetTotal = Bet Total for current game                         dBet = Current Bet              cResponse = Holds 'Y' or 'N' user response*/int iPoint, iWon, iLost = 0;int iDice1, iDice2 = 0;bool bFirstRoll = true;double dBet = 0.00;double dBalance = 0.00;double dBetTotal = 0.00;char cResponse;/* Function Prototypes:          DiceRoll(void)      = Handles our die rolls.  Returns the sum (integer).              Play(int Value) = Evaluate our die roll to scoring. (just for asthetics)   Revision 1:        MakeBet(double Value) = Check balance contains enough to bet.            ManageMoney(void) = Manage changes to balance.               Response(void) = Handle user input.*/int DiceRoll(void);int Play(int);void MakeBet(double);void ManageMoney(void);bool Response(void);using namespace std;int main(void){    /* Seed our random # generator, using time(NULL) as a parameter guarantees       our seed will always be a unique number, guaranteeing random numbers! */    srand(time(NULL));            // Main loop    switch (MODE_AUTOMATIC)    {           case false:                cout << "\nEnter starting bank amount: ";                cin >> dBalance;                while (true)                {                  cout << "\nBank Total $" << dBalance << endl;                  cout << " Bet Total $" << dBetTotal << endl;                                    if (Response()==false)                      break;                                       if (dBalance == 0)                  {                     cout << "\n\nYour broke! Thanks for playing..." << endl;                     break;                  }                  cout << "\nEnter bet amount: ";                     cin >> dBet;                  MakeBet(dBet);                  Play(DiceRoll());                  ManageMoney();                }                break;           case true:                do                 {                  // Directly pass results of DieRoll as parameter to Play(int)                  Play(DiceRoll());                } while ((iWon + iLost) != GAMES_TO_PLAY);                break;    }        cout << "\n\nTotal Wins: "          << iWon          << " Total Losses: "          << iLost          << "\n"          << endl;    cout << "      Odds: " << (static_cast<double>(iWon) / (iWon+iLost) * 100)          << "%"          << endl;    system("PAUSE");    return EXIT_SUCCESS;}bool Response(){   cout << "\nPlay again? ";   cin >> cResponse;   if (cResponse == 'y')   {    return true;   } else {     return false;   }}     // See Function Prototypesvoid ManageMoney(void){     switch (RollResults)     {            case 0:                                     // WIN                 dBalance += (dBetTotal * 2);                 bFirstRoll = true;                 dBetTotal = 0.00;                 break;            case 1:                                     // LOSE                 dBalance -= dBetTotal;                 bFirstRoll = true;                 dBetTotal = 0.00;                 break;            case 2:                                     // AGAIN                 bFirstRoll = false;                 break;     }}// See Function Prototypesvoid MakeBet(double dMoneyToBet){     if ((dMoneyToBet + dBetTotal) > dBalance)      {        cout << "\nAHEM! You don't have that much!\n";        cout << "Maximum bet amount set to bank balance!\n";        // Force the bet total to bank balance if user tries to enter        // a number larger than they have in the bank.        dBetTotal = dBalance;     } else {            dBetTotal += dMoneyToBet;     }}// See Function Prototypesint DiceRoll(void){    iDice1 = (rand() % 6) + 1;    iDice2 = (rand() % 6) + 1;    return(iDice1 + iDice2);}// See Function Prototypesint Play(int Value){    cout << "\nRolled: ";    // bFirstRoll = true if 'Come out Roll'    if (bFirstRoll == true)    {       switch(Value)       {        case  7:        case 11:          RollResults=WIN;          iWon++;          cout << "  Win (" << Value << ") ";          break;        case  2:        case  3:        case 12:          RollResults=LOSE;          iLost++;          cout << " Lost (" << Value << ") ";          break;        default:          cout << "Point (" << Value << ") ";          RollResults=AGAIN;          iPoint = Value;          bFirstRoll = false;          break;        }    cout << iDice1 << " : " << iDice2;    return(Value);    }    // If logic makes here then we only need to test for craps or point    if (Value == 7)    {        cout << "Craps! ";                      RollResults=LOSE;        iLost++;        bFirstRoll = true;    } else if (Value == iPoint)    {        cout << "Point Made! (" << Value << ") ";        RollResults=WIN;        iWon++;        bFirstRoll = true;    }    cout << iDice1 << " : " << iDice2;    return(Value);}