Question
For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter)
For this assignment, write a program that will simulate a single game of Craps.
Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues.
If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately.
If the sum of the first roll of the dice is equal to 2, 3, or 12, the player has rolled "craps" and loses immediately.
If the sum of the first roll of the dice is equal to 4, 5, 6, 8, 9, or 10, the game will continue with the sum becoming the "point." The object of the game is now for the player to continue rolling the dice until they either roll a sum that equals the point or they roll a 7. If the player "makes their point" (i.e. rolls a sum that equals the point), they win. If they roll a 7, they lose.
The random number generator will be used to "roll" the dice.
If a reminder is needed about how to use the random number generator and how to limit the values that are produced, refer back to program 4:
Seed the random number generator with a value of 34. Other seed values may be used to produce different results. However, the version that is handed in for grading MUST use a seed value of 34.
Next, roll the dice by generating two random numbers between 1 and 6. The two numbers should be added together and then displayed along with the sum.
If the sum of the dice is equal to 7 or 11, the game is over and the player has won. Display a congratulatory message.
If the sum of the dice is equal to 2, 3, or 12, the game is over and the player has lost. Display a message indicating the player has lost because they rolled craps.
For any other sum, the sum is now the point and the game should continue until the user rolls the point again or rolls a 7. To do this:
Save the sum (the point) in a variable so it can be used for a later comparison
Display the point
Create a boolean variable and initialize it to a value of true to indicate that the game should continue.
In a loop that executes as long as the game should continue:
o roll the dice and display the two values along with the sum
o if the sum of the dice is the same as the point, display a congratulatory message indicating the player has made their point and they won the game. Also change the boolean variable that controls the loop to false to indicate the game should no longer continue.
o otherwise, if the sum of the dice is 7, display a message that the player has lost the game and change the variable that controls the loop to false to indicate the game should no longer continue.
The program MUST use at least three symbolic constants. Some options are:
an integer for each of the values (2, 3, and 12) that represents craps on the first roll of the die
an integer that represents the value 7
an integer that represents the value 11
1. Include 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 describes what the "chunk" of code does. This will be a part of every program that is submitted during the semester and this will be the last reminder in the program write-ups.
2. Make sure to actually use the symbolic constants that are created.
3. Be sure to #include
4. Make sure that the copy of the program that is handed in uses srand(34); to set the seed value for the random number generator.
For up to 5 points of extra credit, add code that will allow the user to wager that the game will be won. Before the dice are rolled, the user should be prompted for how much they would like to wager on the game. This initial wager is known as the pass line bet. It's a wager that the shooter will win the game (ie. the initial roll is 7 or 11, or the shooter makes their point) (Note: the game of craps also allows the user to wager that the shooter will lose, but we'll leave that out of this implementation.) This wager pays 1/1 or even money. This means that if the user wagers $1, they'll win $1 if the game is won. In other words, if the game is won, the user will win the amount that they wagered plus their original wager. So if the wager amount was $10 and the game is won, the user will win $10 plus get their original wager amount for a total of $20. Like a casino, this implementation of craps will have a minimum wager. Use a value of $5. Make sure to check the user's wager amount and to prompt them for a new value if they enter an amount less than the minimum. This should continue until the user wagers a value greater than or equal to the minimum. Also like a casino, the wager amount must not contain cents. So make sure to use an integer variable to hold the value. 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.
For up to an additional 5 points of extra credit, add code that will allow the user to wager on odds for the pass line wager. This is an additional wager that if a point has been established, the shooter will make the point. After a point has been established but before the dice are rolled to try to make the point, the user should be prompted for how much they would like to wager on the odds that the shooter will make the point. Like extra credit 1, the minimum wager on odds is $5. Make sure to check the user's wager amount and to prompt them for a new value if they enter an amount less than the minimum. This should continue until the user wagers a value greater than or equal to the minimum. Also make sure that the wager amount does not contain cents by using an integer variable. The payouts for wagering on the odds is based upon the point value. Points of 4 and 10 pay 2/1 (if $1 is bet, then the player wins $2 if the 4 or 10 is rolled). Points 5 and 9 pay 3/2 (if $2 is bet, then the player wins $3 if the 5 or 9 is rolled). Points 6 and 8 pay 6/5 (if $5 is bet, then the player wins $6 if the 6 or 8 is rolled). If the point is made, the payout for wagering on the odds is added to the payout for wagering on the pass line (the value from extra credit 1). Use the following formula to calculate the payout for wagering on odds: odds wager amount + ( odds wager amount * odds ) For example, if the point is 8 and user wagered $15 on the odds, the user ends up with $33 for wagering on the odds. wager amount + ( wager amount * odds ) = 15 + ( 15 * 6/5 ) = 15 + ( 90 / 5 ) = 15 + ( 18 ) = 33 If the user wagered $5 on the pass line, then the total payout is $43. $5 from pass line wager plus $5 for making the point plus $15 from wagering on the odds plus $18 for making the point with the odds wager. Note about extra credit 2: the points will ONLY be awarded if the required portions of the assignment work correctly AND extra credit 1 works correctly.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started