Overview: In this lab you will continue working with C++ functions. You will see problems that we have not explicitly discussed in class. You are expected to learn and figure out how things work by looking at the examples given throughout the lab. Before starting, make sure to review the examples and handouts discussed in class.
As you write your programs remember to pay attention to the following issues of style:
Write a program that allows the user to play as many games of Craps as they want and reports the total number of games they played and how many times they won. The user should be able to say 'no', they don't want to play, right away and the program should terminate without playing a single game and print out the appropriate statistics.
A game of Craps is played as follows. The player rolls the dice once.
So, in order to "play" a game of Craps you need to generate dice rolls repeatedly until the player wins or loses according to the above rules. Note that a dice rolls should be simulated by generating two random integers from 1 to 6 with equal probability and adding those two numbers. Generating a single random integer from 1 ro 12 with equal probabiliy does not give you the same probabilities as a real dice roll. To see this, consider there is only one way to roll a total of 2 with real dice, whereas there are multiple different ways of rolling a 7, so the probabilities of these two rolls are not equal.
You should design your program to look as below.
return-type playSingleCrapsGame(parameter-list) { //call a function generateRoll that generates and returns the total value //of a random dice roll //call a function printRoll that prints out this initial value in an //appropriate way (see sample output) loop (as long as the game has not been won or lost) { //call generateRoll function to get another dice roll //send this value to printRoll function to print it //send the necessary values to a function checkGameStatus that //checks to see if the player has won or lost on the current roll //and returns a value indicating teh current game status }//loop //return appropriate value indicating whether the player won or lost } int main() { //variable declaration loop (as long as the user want to play) { //call a function playSingleCrapsGame that plays a single game of craps //and returns a value indicating the outcome (win/lose) //use this value to update a counter variable (or variables) so that //you can print out the gane statistics when the user is done playing //ask if the user wants to play again and call a function that validates //and returns a legal response getUserResponse() }//loop }Your output should look something like the following:
Game 1: You got 11 and won! Do you want to play another game? (y/n) y Game 2: You got 8, 11, 12, 4, 8 and made your point. Do you want to play another game? (y/n) y Game 3: You got 3 and lost! Do you want to play another game? (y/n) y Game 4: You got 5, 9, 8, 7 and crapped out. Do you want to play another game? (y/n) n You played 4 games and won 2 of them.
Send me only the .cpp files in the XCode project. Rename the main.cpp in the XCode folder to something from which I can easily identify the author, the lab number, and the problem number (no spaces in the name, please!)
If you work in a team submit only one file per team.
Make sure you include your name on the top line of all your .cpp programs!!