C++ Programming I Program 4: C++ Craps Game Functions in files, random numbers , stringstream and precision Craps is a popular dice game played in casinos. The C++ variation is as follows: Make a bet. Roll two dice. Each die has six faces, representing values 1-6. Check the sum of the faces showing on the two dice.: If the sum is 2, 3 or 12 (craps), you lose. If the sum is 7 or 11 (natural), you win. If the sum is anything else, a point is established (the sum of the dice you rolled) and you continue to roll until you re-roll the point (you win) or you roll a 7 (you lose). This program will contain 6 functions to be called from main and from another function. The functions will be contained in two files: Functions.h, which contains the function prototypes, and Functions.cpp, which will contain the function implementations (or bodies). Do not forget to put include guards in the Functions.h file. Begin the program by declaring variables and then calling the function WriteHeader. This function will display your name, the program title and objective. Then call ShowRules, which explains the rules. See the random number generator function. This is only done once. Call AskForName to get the player’s name. This functions returns a string with the player’s name. Open a do while or while loop. This is the “play loop,” which allows the user to play craps as many times as he/she wants. Call the function AskForBet to retuun the amount of the user’s bet. The bet minimum is $5.00 and can only be increased in increments of $5.00. The amount of the bet is a double or a float. Assume that the player begins with a balance of $200.00 in his/her pocket. Call ThrowDice, which displays the sum of the values of the faces of the two dice rolled. ThrowDice returns the sum to main. Check the sum to see if the user won, lost, or has to continue. If the player continues, call PlayPointRound, passing the function the point (or the sum of the two dice thrown). PlayPointRound opens a do while loop and calls ThrowDice until the sum is the point or 7. If the point was thrown, it returns true, for a win. If 7 was thrown, it returns false. Keep track of the player’s money balance as he/she plays craps by calling UpdateBalance. Also keep track of the number of wins and losses. Ask the user if s/he wants to play again. Be sure to give the user the choices as an answer. When the user is finished, display a summary of the user’s games, starting with the user’s name, the number of games won, the number of games lost, and the final money balance. Use precision and $ to show money correctly. Then say thank you and goodbye. Function prototypes: Return type Function Name Function Parameters Description void WriteHeader ( ) Write your class header void ShowRules ( ) Display rules of our Craps Game string AskForName ( ) Ask for player’s name double AskYourBet ( ) Ask for player’s bet int ThrowDice ( ) Show sum of the two dice thrown bool PlayPointRound (int dice) Throw until the point is made or 7 double UpdateBalance (bool didWin, double bet) Keep track of the player’s balance
C++
Functions in files, random numbers , stringstream and precision
|
This program will contain 6 functions to be called from main and from another function. The functions will be contained in two files: Functions.h, which contains the function prototypes, and Functions.cpp, which will contain the function implementations (or bodies). Do not forget to put include guards in the Functions.h file.
Begin the program by declaring variables and then calling the function WriteHeader. This function will display your name, the program title and objective. Then call ShowRules, which explains the rules.
See the random number generator function. This is only done once. Call AskForName to get the player’s name. This functions returns a string with the player’s name.
Open a do while or while loop. This is the “play loop,” which allows the user to play craps as many times as he/she wants. Call the function AskForBet to retuun the amount of the user’s bet. The bet minimum is $5.00 and can only be increased in increments of $5.00. The amount of the bet is a double or a float. Assume that the player begins with a balance of $200.00 in his/her pocket.
Call ThrowDice, which displays the sum of the values of the faces of the two dice rolled. ThrowDice returns the sum to main. Check the sum to see if the user won, lost, or has to continue. If the player continues, call PlayPointRound, passing the function the point (or the sum of the two dice thrown). PlayPointRound opens a do while loop and calls ThrowDice until the sum is the point or 7. If the point was thrown, it returns true, for a win. If 7 was thrown, it returns false.
Keep track of the player’s money balance as he/she plays craps by calling UpdateBalance. Also keep track of the number of wins and losses.
Ask the user if s/he wants to play again. Be sure to give the user the choices as an answer. When the user is finished, display a summary of the user’s games, starting with the user’s name, the number of games won, the number of games lost, and the final money balance. Use precision and $ to show money correctly. Then say thank you and goodbye.
Function prototypes:
Return type |
Function Name |
Function Parameters |
Description |
void |
WriteHeader |
( ) |
Write your class header |
void |
ShowRules |
( ) |
Display rules of our Craps Game |
string |
AskForName |
( ) |
Ask for player’s name |
double |
AskYourBet |
( ) |
Ask for player’s bet |
int |
ThrowDice |
( ) |
Show sum of the two dice thrown |
bool |
PlayPointRound |
(int dice) |
Throw until the point is made or 7 |
double |
UpdateBalance |
(bool didWin, double bet) |
Keep track of the player’s balance |
Trending now
This is a popular solution!
Step by step
Solved in 3 steps