Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ please, thank you in advance! Lab 4 (function) Problem 1. (Game: craps) Craps is a popular dice game played in casinos. Write a program
C++ please, thank you in advance!
Lab 4 (function) Problem 1. (Game: craps) Craps is a popular dice game played in casinos. Write a program to play a variation of the game, as follows: Roll two dice. Each diece has six faces representing values 1,2,, and 6 , respectively. Check the sum of the two dice. If the sum is 2,3 or 12 (called craps), you lose; if the sum is 7 or 11 (called natural), you win; if the sum is another value (i.e. 4,5,6,8,9,10 ), a point is established. Continue until you roll either 7 (you lose) or the same point value (you win). Your program acts as a single player. Here are some sample runs. Example1: you rolled 5+6=11 You win Example2: you rolled 1+2=3 You lose Example3: you rolled 4+4=8 Point is 8 You rolled 6+2=8 You win Example4: you rolled 3+2=5 Point is 5 You rolled 2+5=7 You lose Make sure that you use functions to implement subtasks and call these functions in your main function. (Hint: function rand() will return you a random number) HOW TO PROCEED (from Prof. Tausner) The final version of your program will be playing the game 10,000 times, but first get it working to play one game correctly. I suggest you design your program to play one game as follows: You will be using a random number generator to get a number from 1 to 6 for each roll of the dice. Your program should be written using at least one function, which should roll the two dice and figure out the score. Good programming practice would be to first write and test the program to play one qame. It should thoroughly test the dice rolling function to make sure it works. 1) print out the value of "the point" after the first roll, 2) in the dice rolling function, print out the 2 random numbers you get to simulate the roll of 2 dice, 3) print out the result - whether the player won or lost that game. To play 10,000 qames Set up a counter for the player's wins and a counter for the player's losses Loop 10000 times to play 10000 games At the end of the program compute the probability of a player winning as probability = wins / (wins + losses ) You'll probably want to comment out all the intermediate print outs, and just print out how mary games were won by the player, how many games were lost by the player, and the probability of a player winningStep 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