1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <iostream>
#include<cstdlib>
#include<iomanip>
#include "rolldice.cpp"
//******************************************************************************
using namespace std;
int main()
{
const int LUCKY_SEVEN = 7,
CRAPS = 7,
YO_LEVEN = 11,
SNAKE_EYES = 2,
TREY = 3,
BOX_CARS = 12;
const double MINIMUM = 500.00;
int die1, die2, point, dieSum;
double purse, bet;
bool won, quit;
char response;
purse=1000;
void rolldice(int& die1, int& die2);
cout<<"This program will simulate the game of craps and will allow you to bet\n"
<<"a certain amount of money. Based on your roll, you will win or lose money.\n"
<<"If on your first roll, you roll a 7 or an 11, you will win (Craps Out!)\n"
<<"Until you Crap Out, you will continue to roll. Your starting amount of\n"
<<"money is $1000. You will win or loose money based upon what you have\n"
<<"wagered. Good luck!.\n\n";
cout<<"You have "<< purse <<" dollars, you will be asked to place a bet until\n"
<<"you run out.\n";
if (purse<MINIMUM)
{
cout<<"You must exit the game so that you can restart the value in your purse.\n";
}
do
{
cout<<"You have"<< purse <<"dollars to start with.\n";
do
{
cout<<"Please enter a valid bet, bet must be greater or equal to $500.\n";
cin>>bet;
do
{
cout<<"You have bet "<< bet <<"dollars. Let us roll now...\n";
}while(bet <500 || bet!=0);
cout<<"Roll the dice!\n";
system("PAUSE");
rolldice(die1,die2);
dieSum = die1 + die2;
cout<<"You rolled a "<<die1 + die2<<".\n";
switch (dieSum)
{
case LUCKY_SEVEN:
case YO_LEVEN: won = true;
break;
case SNAKE_EYES:
case TREY:
case BOX_CARS: won = false ;
break;
default: point = dieSum;
cout<<"Your roll, "<<die1 + die2 <<"becomes your point.\n";
do
{
cout<<"Roll the dice!\n";
system("PAUSE");
rolldice(die1,die2);
dieSum = die1 + die2;
}while(dieSum != CRAPS);
switch (dieSum)
{
case LUCKY_SEVEN:
case YO_LEVEN: won = false;
break;
case SNAKE_EYES:
case TREY:
case BOX_CARS: won = true ;
break;
default: point = dieSum;
// set won to true or false depending on outcome of dieSum
if(won)
{
cout<<"Congratulations, you have won. Your purse is now "<<purse + bet <<"!\n";
}
else
{
cout<<"Unfortunately you have lost, your purse is now "<< purse - bet <<"...\n";
}
if(purse!=0)
{
cout<<"You have "<< purse <<"!Cool...\n";
}
do
{
cout<<"Would you like to play again?\n";
cin>>response;
response = toupper(response);
if(response != 'Y' && response != 'N');
cout<<"Illegal response, please answer Y for yes or N for No:\n";
}while(response != 'Y' && response != 'N');
if(response=='N')
{
cout<<"Ok then...\n";
}
else( purse == 0 )
{
cout<<"Please exit and reenter the game to restart the amount you have in your purse.\n";
}while(purse!=0);
cout<<"Please come back soon.\n";
system("PAUSE");
return 0;
}
|