Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A popular game of chance is called “craps,” which is played in casinos and back

ID: 3624026 • Letter: A

Question

A popular game of chance is called “craps,” which is played in casinos and back alleys. The
rules of the game are the following:
A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5 and 6 spots.
After the dice have come to rest, the sum of the spots on the two upward faces is calculated.
If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3 or 12 on the first roll
(called “craps”), the player loses. If the sum is 4, 5, 6, 8, 9 or 10 on the first roll, then that
sum becomes the player's “point.” To win, the player must continue rolling the dice until
he/she “makes point.” The player loses by rolling a 7 before the point.
Package, as a function, the portion of the program that runs one game of craps. Create a
variable that keeps track of the player's balance, initially this value should be $1,000. Prompt
the player to enter a wager. Check to make sure that the player has enough money to cover
the wager. Call the craps game function and if the player wins, increase the balance by the
amount of the wager. If the player looses, decrease the balance by the amount of the wager.
If the balance becomes zero, print the message “Sorry, you are busted!” and end the game.
Have the game create some chatter, such as “Oh, you are going broke!” or “Take a chance” or
“You are up big. Now is the time to cash in your chips!” or whatever else you would like.
Comments must be relative to the players balance.
Your code should be modular, well constructed and make extensive use of functions. All user
input should be tested for validity. Be sure to print out the the values of each dice, the status
of the roll (i.e. win, lose, roll-again). At the end of each game the user should see a balance of
the money in their account. Make proper use of constants and ask the user if they would like
to continue to play or cash in their chips. Try to make the game as fun and entertaining as
possible.

Explanation / Answer

#include<iostream>
using std::cout;
using std::cin;
using std::endl;
// contains prototypes for functions rand & srand
# include <cstdlib>
using std::rand;
using std::srand;
// contains prototype for function time
# include <ctime>
using std::time;

int rollDice();
bool craps();

int main()
{
int bankBalance = 100;
int wager;


while (bankBalance > 0)
{

while (true)
{

cout << " Enter your wager : ";
cin >> wager;


if (bankBalance < wager)
cout << " Your bank balance is low. "
<< " Please enter a valid wager : ";
else
break;
}


if (craps())
{

bankBalance = bankBalance + wager;
if (rand()%2)
cout << " Aw cmon, take a chance!";
else
cout <<" You're up big. Now's the time to cash in your chips ";
}

else
{

bankBalance = bankBalance - wager;
if (rand()%2)
cout << " Aw cmon, take a chance!";
else
cout << " Oh, you're going for broke, huh ? ";
}

cout << " Your bank balance is " << bankBalance;


}

cout << " Sorry, You busted!";
return 0;
}


bool craps()
{
enum Status {CONTINUE, WON, LOST};
int myPoint;

Status gameStatus;
srand(time(0));
int sumOfDice = rollDice();

switch (sumOfDice)
{
case 7 :
case 11 : gameStatus = WON;
break;

case 2 :
case 3 :
case 12 : gameStatus = LOST;
break;

default : gameStatus = CONTINUE;
myPoint = sumOfDice;
break;
}


while (gameStatus == CONTINUE)
{
sumOfDice = rollDice();

if (sumOfDice == myPoint)
gameStatus = WON;
else
if (sumOfDice == 7)
gameStatus = LOST;
}


if (gameStatus == WON)
return true;
else
return false;
}


int rollDice()
{
int die1 = 1 + rand() % 6;
int die2 = 1 + rand() % 6;
int sum = die1 + die2;

return sum;
}



I hope this helps!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote