CS 107 - Machine Problem 2

Craps - Due: 2/17/2003 at 2:00 pm

For this program, we will simulate the dice rolls for a game of craps. This program will only determine in the "roller" wins or loses the games and not how the betting is done at a casino.

The game uses two six-sided dice. Each die ("die" is the singular of "dice") will produce a value from 1 to 6. The results of the two dice will be added together to produce a final result from 2 to 12. One of three things happen based on the result of the first dice roll of the game:

  1. The result is either 7 or 11. In this case, the roller wins and the game is over.

  2. The result is either 2, 3 or 12. In this case, the roller loses and the game is over.

  3. The result is either 4, 5, 6, 8, 9 or 10. In this case, the roller sets the "point" value and more dice rolls must be made to determine if the roller wins or loses.

Your program must use a random number generator that will produce the numbers from 1 to 6 for each die with equal probability. The library cstdlib contains some functions to use with the random number generator. Check out page 867 of the book.

For each game, your program is to show all dice rolls (show the value for each die and the total) and provide the proper commentary on how the game is progressing. Your program should provide all of these dice rolls without any interaction with the user.

Once each game is over, your program should prompt the user to see if they wish to play another game. Your program should expect the user to type in y or n for yes (play another game) or no (do not play another game). If the user enters anything other than y or n, assume the player wants to play another game. Your program must also make sure that if another game is played, only one game is played before the user is prompted again to play another game. You should check out the library function of get for ideas on how to make this work. Check the book's index for pages that discuss get.

When the user does not wish to play any more games, print out some simple statistics about games played. This information is to show:

  1. The number of games played
  2. The number and percentage of games won
  3. The number and precentage of games lost
  4. The number and percentage of games won on the first roll
  5. The number and percentage of games lost on the first roll
  6. The number of games in which a "point" was set (i.e. required more than one roll to determine the outcome of the game)
  7. The number of games in which the "point" was won
  8. The number of games in which the "point" was lost

The following is an example of how the output COULD look like (your program is not required to look exactly like this, but this output contains all of the required information). Any user entered input is listed in bold print.

     Welcome to the CS 107 Craps Rolling Program
     Written by: Edmond Hoyle

     Starting game 1
      Roll 1 - D1: 2, D2: 5, Total: 7, You win!

     Do you wish to play another game? (y/n): y

     Starting game 2
      Roll 1 - D1: 6, D2: 5, Total: 11, You win!

     Do you wish to play another game? (y/n): y

     Starting game 3
      Roll 1 - D1: 2, D2: 1, Total: 3, You lose!

     Do you wish to play another game? (y/n): y

     Starting game 4
      Roll 1 - D1: 2, D2: 4, Total: 6, The point is 6
      Roll 2 - D1: 4, D2: 5, Total: 9, Keep Rolling
      Roll 3 - D1: 1, D2: 2, Total: 3, Keep Rolling
      Roll 4 - D1: 3, D2: 3, Total: 6, You rolled the point and won!

     Do you wish to play another game? (y/n): y

     Starting game 5
      Roll 1 - D1: 5, D2: 4, Total: 9, The point is 9
      Roll 2 - D1: 4, D2: 2, Total: 6, Keep Rolling
      Roll 3 - D1: 1, D2: 6, Total: 7, You rolled a 7 and lost!

     Do you wish to play another game? (y/n): n

     You played 5 games.
     You won 3 games (60%)
     You lost 2 games (40%)
     You won 2 games on the first roll (40%)
     You lost 1 game on the first roll (20%)
     You played 2 games in which a point was set
     You won 1 game in which a point was set
     You lost 1 game in which a point was set

     Thank you for playing the CS 107 Craps Rolling Program
     Goodbye

Your program must be written using good programming style. This includes (but is not limitted to) such items as:

Your program will be submitted electronically on the icarus system using the turnin command. The project name for this will be mp2. Your program will graded based on how it executes on the icarus system using the g++ compiler. Getting a program to work on another system or using another compiler does NOT mean it will work on the icarus system using the g++ compiler. Programs that do not work properly on the icarus system using the g++ compiler will lose points. Also programs that are not submitted via the turnin command will also lose points. Emailing a program is not an acceptable form of electronic submission.