Programming Language: C++
Overview
For this assignment, write a program that will simulate a singlegame of Craps.
Craps is a game of chance where a player (the shooter) will roll2 six-sided dice. The sum of the dice will determine whether theplayer (and anyone that has placed a bet) wins immediately, losesimmediately, 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, or12, 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 rollingthe dice until they either roll a sum that equals the point or theyroll a 7. If the player \"makes their point\" (ie. rolls a sum thatequals 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 numbergenerator and how to limit the values that are produced, refer backto program 4:
Link to Program 4
Basic Program Logic
Seed the random number generator with a value of 22. Note: otherseed values may be used to produce different results. However, theversion that is handed in for grading MUST use a seed value of22.
Next, roll the dice by generating two random numbers between 1and 6. The two numbers should be added together and then displayedalong with the sum.
If the sum of the dice is equal to 7 or 11, the game is over andthe player has won. Display a congratulatory message.
If the sum of the dice is equal to 2, 3, or 12, the game is overand the player has lost. Display a message indicating the playerhas lost because they rolled craps.
For any other sum, the sum is now the point and the game shouldcontinue until the user rolls the point again or rolls a 7. To dothis:
Save the sum (the point) in a variable so it can be used for alater comparison
Display the point
Create a boolean variable and initialize it to a value of trueto 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 acongratulatory message indicating the player has made their pointand they won the game. Also change the boolean variable thatcontrols the loop to false to indicate the game should no longercontinue.
otherwise, if the sum of the dice is 7, display a message thatthe player has lost the game and change the variable that controlsthe loop to false to indicate the game should no longercontinue.
Symbolic Constants
The program MUST use at least three symbolic constants. Someoptions are:
an integer for each of the values (2, 3, and 12) that representscraps on the first roll of the die
an integer that represents the value 7
an integer that represents the value 11
Program Requirements
Include line documentation. There is no need to document everysingle line, but logical \"chunks\" of code should be preceded by aline or two that describes what the \"chunk\" of code does.This will be a part of every program that is submittedduring the semester and this will be the last reminder in theprogram write-ups.
Make sure to actually use the symbolic constants that arecreated.
Be sure to #include
Make sure that the copy of the program that is handed in usessrand(22); to set the seed value for the random numbergenerator.
Hand in a copy of the source code (CPP file) usingBlackboard.
Output
Some runs of the program follow. Each one is marked with thesrand value that produced the result.
Run 1 using srand(11); on Windows PC
Roll: 3 + 1 = 4 The point is 4 Roll: 5 + 4 = 9 Roll: 6 + 6 = 12Roll: 1 + 2 = 3 Roll: 3 + 2 = 5 Roll: 3 + 2 = 5 Roll: 1 + 1 = 2Roll: 6 + 1 = 7 Seven'd out! You lost!
Run 2 using srand(14); on Windows PC
Roll: 1 + 6 = 7 You won! Congratulations!
Run 3 using srand(22); on Windows PC
Roll: 3 + 1 = 4 The point is 4 Roll: 5 + 1 = 6 Roll: 4 + 4 = 8Roll: 6 + 6 = 12 Roll: 4 + 4 = 8 Roll: 2 + 1 = 3 Roll: 5 + 1 = 6Roll: 2 + 4 = 6 Roll: 3 + 5 = 8 Roll: 5 + 3 = 8 Roll: 2 + 1 = 3Roll: 2 + 2 = 4 The point was made! You won!
Run 4 using srand(1); on Windows PC
Roll: 6 + 6 = 12 Craps! You lost!
Run 1 using srand(11); on Mac
Roll: 6 + 5 = 11 You won! Congratulations!
Run 2 using srand(22); on Mac
Roll: 5 + 3 = 8 The point is 8 Roll: 5 + 5 = 10 Roll: 6 + 5 = 11Roll: 6 + 1 = 7 Seven'd out! You lost!
Run 3 using srand(1); on Mac
Roll: 2 + 2 = 4 The point is 4 Roll: 6 + 3 = 9 Roll: 5 + 3 = 8Roll: 1 + 3 = 4 The point was made! You won!
Run 4 using srand(5); on Mac
Roll: 6 + 6 = 12 Craps! You lost!
Extra Credit 1
For up to 5 points of extra credit, add code that will allow theuser to wager that the game will be won.
Before the dice are rolled, the user should be prompted for howmuch they would like to wager on the game. This initial wager isknown as the pass line bet. It's a wager that the shooter will winthe game (ie. the initial roll is 7 or 11, or the shooter makestheir point) (Note: the game of craps also allows the user to wagerthat the shooter will lose, but we'll leave that out of thisimplementation.)
This wager pays 1/1 or even money. This means that if the userwagers $1, they'll win $1 if the game is won. In other words, ifthe game is won, the user will win the amount that they wageredplus their original wager. So if the wager amount was $10 and thegame is won, the user will win $10 plus get their original wageramount for a total of $20.
Like a casino, this implementation of craps will have a minimumwager. Use a value of $5. Make sure to check the user's wageramount and to prompt them for a new value if they enter an amountless than the minimum. This should continue until the user wagers avalue greater than or equal to the minimum.
Also like a casino, the wager amount must not contain cents. Soa wager of $5.25 should not be allowed. If the user adds cents totheir wager amount, \"return\" the cents to the user and use theremaining amount as the wager amount. So if the user tries towager, $5.25 the $0.25 should be \"returned\" and the wager amountadjusted to $5. There are a number of ways to check for digitsafter the decimal point (cents). One way is to take the originalwager amount and subtract the integer portion of the wageramount.
Note about extra credit: the points will ONLY be awardedif the required portions of the assignment work correctly. In otherwords, don't take short cuts in the rest of the program because itis assumed that 5 extra points will be awarded.
Extra Credit 1 Output 1 using srand(11); on WindowsPC
How much would you like to wager (no cents allowed) (minimum:5.00)? 10.00 Roll: 3 + 1 = 4 The point is 4 Roll: 5 + 4 = 9 Roll: 6+ 6 = 12 Roll: 1 + 2 = 3 Roll: 3 + 2 = 5 Roll: 3 + 2 = 5 Roll: 1 +1 = 2 Roll: 6 + 1 = 7 Seven'd out! You lost! You lost $10.00
Extra Credit 1 Output 2 using srand(22); on WindowsPC
How much would you like to wager (no cents allowed) (minimum:5.00)? 10.00 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: 2 + 1 = 3 Roll: 5 +1 = 6 Roll: 2 + 4 = 6 Roll: 3 + 5 = 8 Roll: 5 + 3 = 8 Roll: 2 + 1 =3 Roll: 2 + 2 = 4 The point was made! You won! You won $20.00
Extra Credit 1 Output 3 using srand(15); on WindowsPC
How much would you like to wager (no cents allowed) (minimum:5.00)? 2.50 You can't bet $2.50. The minimum bet is 5.00. Pleasetry again: 1.00 You can't bet $1.00. The minimum bet is 5.00.Please try again: 5.36 You can have 0.36 back. The wager cannothave cents. Your wager is now 5.00 Roll: 4 + 6 = 10 The point is 10Roll: 3 + 5 = 8 Roll: 6 + 3 = 9 Roll: 1 + 1 = 2 Roll: 3 + 4 = 7Seven'd out! You lost! You lost $5.00
Extra Credit 1 Output 1 using srand(1); onMac
How much would you like to wager (no cents allowed) (minimum:5.00)? 5.00 Roll: 2 + 2 = 4 The point is 4 Roll: 6 + 3 = 9 Roll: 5+ 3 = 8 Roll: 1 + 3 = 4 The point was made! You won! You won$10.00
Extra Credit 1 Output 2 using srand(5); onMac
How much would you like to wager (no cents allowed) (minimum:5.00)? 5 Roll: 6 + 6 = 12 Craps! You lost! You lost $5.00
Extra Credit 1 Output 3 using srand(22); onMac
How much would you like to wager (no cents allowed) (minimum:5.00)? 5.00 Roll: 5 + 3 = 8 The point is 8 Roll: 5 + 5 = 10 Roll: 6+ 5 = 11 Roll: 6 + 1 = 7 Seven'd out! You lost! You lost $5.00
Extra Credit 2
For up to an additional 5 points of extra credit, add code thatwill allow the user to wager on odds for the pass line wager. Thisis an additional wager that if a point has been established, theshooter will make the point.
After a point has been established but before the dice arerolled to try to make the point, the user should be prompted forhow much they would like to wager on the odds that the shooter willmake the point.
Like extra credit 1, the minimum wager on odds is $5. Make sureto check the user's wager amount and to prompt them for a new valueif they enter an amount less than the minimum. This should continueuntil the user wagers a value greater than or equal to theminimum.
Also make sure that the wager amount does not contain cents. Ifit does, \"return\" the cents and adjust the wager amount to removethe cents.
The payouts for wagering on the odds is based upon the pointvalue. Points of 4 and 10 pay 2/1 (if $1 is bet, then the playerwins $2 if the 4 or 10 is rolled). Points 5 and 9 pay 3/2 (if $2 isbet, then the player wins $3 if the 5 or 9 is rolled). Points 6 and8 pay 6/5 (if $5 is bet, then the player wins $6 if the 6 or 8 isrolled).
If the point is made, the payout for wagering on the odds isadded to the payout for wagering on the pass line (the value fromextra credit 1).
Use the following formula to calculate the payout for wageringon odds:
wager amount + ( 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 payoutis $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 withthe odds wager.
Note about extra credit 2: the points will ONLY beawarded if the required portions of the assignment work correctlyAND extra credit 1 works correctly.
Extra Credit 2 Output 1 using srand(22); on WindowsPC
How much would you like to wager (no cents allowed) (minimum:5.00)? 10.00 Roll: 3 + 1 = 4 The point is 4 How much would you liketo wager on the odds? 30.00 Roll: 5 + 1 = 6 Roll: 4 + 4 = 8 Roll: 6+ 6 = 12 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: 2 + 1 = 3 Roll: 2 + 2 =4 The point was made! You won! Pass Line Win: $20.00 Odds Payout:$90.00 You won $110.00
Extra Credit 2 Output 2 using srand(4); on WindowsPC
How much would you like to wager (no cents allowed) (minimum:5.00)? 5.00 Roll: 4 + 6 = 10 The point is 10 How much would youlike to wager on the odds? 1.25 You can't bet $1.25. The minimumbet is 5.00. Please try again: 10.36 You can have 0.36 back. Thewager cannot have cents. Your wager is now 10.00 Roll: 4 + 3 = 7Seven'd out! You lost! You lost $15.00
Extra Credit 2 Output 1 using srand(1); onMac
How much would you like to wager (no cents allowed) (minimum:5.00)? 5.00 Roll: 2 + 2 = 4 The point is 4 How much would you liketo wager on the odds? 10.00 Roll: 6 + 3 = 9 Roll: 5 + 3 = 8 Roll: 1+ 3 = 4 The point was made! You won! Pass Line Win: $10.00 OddsPayout: $30.00 You won $40.00