Description
For this assignment, expand on Program 4 (the craps game) by adding in the use of functions and allowing the user to wager on the game.
Processing Requirements
This program should allow the user to play more than one game of craps. This means that the code that simulated the game play in program 4 should be placed in a loop. The loop should be controlled by asking the user if they would like to keep playing and if they have enough money to keep playing. The user will answer ‘Y’ or ‘y’ to indicate they would like to play the game again. If you did the extra credit portion from program 4, this part of the new program is already done. As for the money, the user must have at least the minimum wager amount (see below) to continue playing. If the user would like to keep playing but they don’t have enough money, display a message that tells them they do not have enough money and do not allow them to continue the game.
The other changes for this program will involve using functions. There will be one function that will handle the rolling of the dice and another that will get the amount that the user wants to wager on a single game of craps.
The introduction of wagering also means that some code will have to be added to int main() to keep track of the user’s balance (or bank). Every instance where the user can win the game of craps will require the addition of code to increase the user’s balance by the amount that they wagered. Every instance where the user can lose the game will require the addition of code to decrease the user’s balance by the amount that was wagered. The user will start with a balance of $100.00 and the minimum amount that they can wager is $5.00. Note: this program will not be handling the true odds from the game of craps. The user will simply win or lose whatever money they wager. Never more and never less.
Once the game is over, display the user’s final balance amount.
The Functions
For this program, there are two required functions:
int rollDice()
This function will handle the rolling of the two die, calculating the sum of the dice, displaying the dice and the sum, and then returning the calculated sum.
The function takes no argument. It returns an integer value that represents the sum of the dice.
As with program 4, the value for each die must be between 1 and 6, inclusive.
double getWager( double balanceAmount )
This function will get and return a desired (valid) wager amount from the user.
The function takes one argument: a double value that represents the user’s current balance. It returns a double value that represents the amount of the user’s wager.
The code for this function should prompt the user for the amount that he/she would like to wager. The prompt should include the user’s current balance and the amount of the minimum wager ($5.00). The amount that is entered by the user must be a valid value, meaning that it must be between the minimum wager amount and the user’s balance, inclusive. If the user enters an invalid wager amount, an error message should be displayed and the user should be given a chance to re-enter the wager amount. This should continue until the user enters a valid wager amount. Once a valid amount has been entered, it should be returned to the function that called the getWager function.
Note: the error message should include the invalid wager amount.
Program Requirements
-
- As with the previous assignment and the assignments until the end of the semester, complete program documentation is required. For this assignment, that means that line documentation AND function documentation boxes are needed. In regards to line documentation, there is no need to document every single line, but logical “chunks” of code should be preceded by a line or two that describe what the “chunk” of code does.
Each function must have a documentation box explaining:
-
-
- its name
- its use or function: that is, what does it do? What service does it provide to the code that calls it?
- a list of its arguments briefly describing the meaning and use of each
- the value returned (if any) or none
- notes on any unusual features, assumptions, techniques, etc.
-
/*************************************************************** Function: int rollDice() Use: This function rolls the dice for the game of craps Arguments: None Returns: the sum of the dice Note: the function will display the two die and their sum as well ***************************************************************/
See the documentation standards on the course webpage for more examples or if further clarification is needed. Your program will not get full credit (even if it works correctly) if these standards are not followed
- All of the dollar amounts in the output should be displayed with a leading dollar sign and EXACTLY two digits after the decimal point.
- Hand in a copy of the source code (CPP file) using Blackboard.
Output
You have $100.00 available. How much would you like to wager (Minimum wager: $5.00)? 20 Player rolled: 3 + 1 = 4 The point is 4 Player rolled: 1 + 3 = 4 You rolled your point! You won! Your balance is $120.00 Would you like to keep playing (y for yes)? y You have $120.00 available. How much would you like to wager (Minimum wager: $5.00)? 130 You cannot wager $130.00. Try again: 4 You cannot wager $4.00. Try again: 75 Player rolled: 3 + 4 = 7 You won! Your balance is $195.00 Would you like to keep playing (y for yes)? y You have $195.00 available. How much would you like to wager (Minimum wager: $5.00)? 175 Player rolled: 1 + 5 = 6 The point is 6 Player rolled: 2 + 4 = 6 You rolled your point! You won! Your balance is $370.00 Would you like to keep playing (y for yes)? y You have $370.00 available. How much would you like to wager (Minimum wager: $5.00)? 300 Player rolled: 5 + 5 = 10 The point is 10 Player rolled: 1 + 4 = 5 Player rolled: 4 + 2 = 6 Player rolled: 4 + 3 = 7 You seven'd out and lost! Your balance is $70.00 Would you like to keep playing (y for yes)? n Your final balance is $70.00
or
Using srand(4)
You have $100.00 available. How much would you like to wager (Minimum wager: $5.00)? 50 Player rolled: 4 + 6 = 10 The point is 10 Player rolled: 4 + 3 = 7 You seven'd out and lost! Your balance is $50.00 Would you like to keep playing (y for yes)? y You have $50.00 available. How much would you like to wager (Minimum wager: $5.00)? 35 Player rolled: 6 + 1 = 7 You won! Your balance is $85.00 Would you like to keep playing (y for yes)? y You have $85.00 available. How much would you like to wager (Minimum wager: $5.00)? 12 Player rolled: 2 + 3 = 5 The point is 5 Player rolled: 5 + 3 = 8 Player rolled: 6 + 6 = 12 Player rolled: 1 + 1 = 2 Player rolled: 5 + 4 = 9 Player rolled: 4 + 3 = 7 You seven'd out and lost! Your balance is $73.00 Would you like to keep playing (y for yes)? y You have $73.00 available. How much would you like to wager (Minimum wager: $5.00)? 60 Player rolled: 6 + 5 = 11 You won! Your balance is $133.00 Would you like to keep playing (y for yes)? y You have $133.00 available. How much would you like to wager (Minimum wager: $5.00)? 125 Player rolled: 5 + 2 = 7 You won! Your balance is $258.00 Would you like to keep playing (y for yes)? Y You have $258.00 available. How much would you like to wager (Minimum wager: $5.00)? 250 Player rolled: 4 + 6 = 10 The point is 10 Player rolled: 6 + 5 = 11 Player rolled: 2 + 4 = 6 Player rolled: 4 + 5 = 9 Player rolled: 3 + 6 = 9 Player rolled: 1 + 6 = 7 You seven'd out and lost! Your balance is $8.00 Would you like to keep playing (y for yes)? y You have $8.00 available. How much would you like to wager (Minimum wager: $5.00)? 5 Player rolled: 2 + 4 = 6 The point is 6 Player rolled: 5 + 1 = 6 You rolled your point! You won! Your balance is $13.00 Would you like to keep playing (y for yes)? y You have $13.00 available. How much would you like to wager (Minimum wager: $5.00)? 10 Player rolled: 5 + 2 = 7 You won! Your balance is $23.00 Would you like to keep playing (y for yes)? y You have $23.00 available. How much would you like to wager (Minimum wager: $5.00)? 22 Player rolled: 2 + 2 = 4 The point is 4 Player rolled: 1 + 3 = 4 You rolled your point! You won! Your balance is $45.00 Would you like to keep playing (y for yes)? y You have $45.00 available. How much would you like to wager (Minimum wager: $5.00)? 44 Player rolled: 1 + 1 = 2 You rolled craps. You lost Your balance is $1.00 Would you like to keep playing (y for yes)? y I'm sorry but you do not have enough money to continue playing. Your final balance is $1.00
Extra Credit
For up to 5 points of extra credit, add and use two function that will add some “chatter” to the game.
void wagerChatter( double balanceAmt, double wagerAmt )
This function will be called after the player makes a wager on the game. If the user bets an extreme (either high or low) amount, a message should be displayed to the player. For the high extreme, if the player wagers at least 75% of their balance amount, display something like “Oh, you’re going for broke, huh?.” For the low extreme, if the player wagers less than 7% of their balance amount, display something like “Aw cmon, take a chance next time!”
The function takes two arguments: a double that represents the player’s balance amount and a double that represents the player’s wager amount. It returns nothing.
void continueChatter( double balanceAmt )
This function will be called after the player decides to continue the game. It will display a message based on the player’s balance. If the player has a balance of $0.00, display something like “Sorry! You busted! You can’t keep playing.” If the balance is less than the minimum wager, display something like “I’m sorry but you do not have enough money to continue playing.” If the balance is more than 5 times the starting balance, display something like “You’re up big. You should think about cashing in your chips after this game!”
The function takes one argument: a double that represents the player’s balance amount. It returns nothing.
Note about extra credit: the points will ONLY be awarded if the required portions of the assignment work correctly. In other words, don’t take short cuts in the rest of the program because it is assumed that 5 extra points will be awarded.
Extra Credit Output
You have $100.00 available. How much would you like to wager (Minimum wager: $5.00)? 78 Oh, you're going for broke, huh? Player rolled: 6 + 5 = 11 You won! Your balance is $178.00 Would you like to keep playing (y for yes)? y You have $178.00 available. How much would you like to wager (Minimum wager: $5.00)? 5 Aw cmon, take a chance next time! Player rolled: 1 + 6 = 7 You won! Your balance is $183.00 Would you like to keep playing (y for yes)? y You have $183.00 available. How much would you like to wager (Minimum wager: $5.00)? 150 Oh, you're going for broke, huh? Player rolled: 3 + 4 = 7 You won! Your balance is $333.00 Would you like to keep playing (y for yes)? y You have $333.00 available. How much would you like to wager (Minimum wager: $5.00)? 300 Oh, you're going for broke, huh? Player rolled: 5 + 3 = 8 The point is 8 Player rolled: 5 + 4 = 9 Player rolled: 3 + 1 = 4 Player rolled: 3 + 6 = 9 Player rolled: 4 + 6 = 10 Player rolled: 1 + 3 = 4 Player rolled: 4 + 2 = 6 Player rolled: 3 + 4 = 7 You seven'd out and lost! Your balance is $33.00 Would you like to keep playing (y for yes)? n Your final balance is $33.00