Question: C++ Program For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player
C++ Program 





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. Random Number Generation 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: roll the dice and display the two values along with the sum 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. 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. Symbolic Constants 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 Program Requirements 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. 5. Hand in a copy of the source code (CPP file) using Blackboard. Output Some runs of the program follow. Each one is marked with the srand value that produced the result. Output 1 using srand(34); on Windows PC Rol1: 6+4=10 The point is 10 Roll: 5+4=9 Roll: 5+3=8 Roll: 3+1=4 Roll: 5+1=6 Roll: 3+1=4 Roll: 3+5=8 Roll: 6+5=11 Roll: 1+2=3 Roll: 2+1=3 Roll: 6+6=12 Roll: 6+3=9 Roll: 4+2=6 Roll: 5+1=6 Roll: 3+5=8 Rol1: 1+2=3 Roll: 6+3=9 Roll: 2+6=8 Roll: 6+1=7 Seven'd out! You lose! Output 2 using srand(19); on Windows PC Roll: 5+2=7 Seven! Winner! Output 3 using srand(22); on Windows PC Roll: 3+1=4 The point is 4 Roll: 5+1=6 Roll: 4+4=8 Roll: 6+6=12 Roll: 4+4=8 Roll: 4+4=8 Roll: 2+1=3 Roll: 5+1=6 Roll: 2+4=6 Roll: 3+5=8 Roll: 5+3=8 Roll: 5+3=8 Roll: 2+1=3 Roll: 2+2=4 The point was made! Winner! Output 4 using srand(1); on Windows PC Rol1: 6+6=12 Craps! You lose! Output 1 using srand(34); on Mac Roll: 5+1=6 The point is 6 Roll: 2+6=8 Roll: 5+2=7 Seven'd out! You lose! Output 2 using srand(28); on Mac Rol1: 5+2=7 Seven! Winner! Extra Credit 2 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. 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. Extra Credit 2 Output 1 using srand(34); on Windows PC What's your wager (minimum: \$5)? 10 Roll: 6+4=10 The point is 10 How much would you like to wager on the odds? 25 Roll: 5+4=9 Roll: 5+3=8 Roll: 3+1=4 Roll: 5+1=6 Roll: 3+1=4 Roll: 3+5=8 Roll: 6+5=11 Roll: 1+2=3 Roll: 2+1=3 Roll: 6+6=12 Roll: 6+3=9 Roll: 4+2=6 Roll: 5+1=6 Roll: 3+5=8 Rol1: 1+2=3 Roll: 6+3=9 Roll: 2+6=8 Roll: 6+1=7 Seven'd out! You lose! You lost $35.00 Extra Credit 2 Output 2 using srand(9); on Windows PC What's your wager (minimum: \$5)? 2 You can't bet $2. The minimum bet is $5. Please try again: 4 You can't bet $4. The minimum bet is $5. Please try again: 3 You can't bet $3. The minimum bet is $5. Please try again: 15 Roll: 3+2=5 The point is 5 How much would you like to wager on the odds? -7 You can't wager \$-7 on the odds. The minimum odds wager is \$5. Please try again: 1 You can't wager $1 on the odds. The minimum odds wager is $5. Please try again: 2 You can't wager $2 on the odds. The minimum odds wager is $5. Please try again: 20 Rol1: 2+1=3 Roll: 5+6=11 Roll: 4+1=5 The point was made. Winner! Pass Line Win: $30.00
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
