back
The Game of Craps
Craps is a dice game with the following rules:

  • The game is played wih two dice.
  • A 7 or 11 on the first toss means an automatic win (called a "nick").
  • A 2, 3, or 12 on the first toss means automatic lose (called a "crap").
  • If the player tosses 4, 5, 6, 8, 9, or 10, then that number becomes the player's "point."
  • The player repeats tossing until he wins by tossing his point a second time or loses by tossing a 7.

    Let's take a look at the possible outcomes:

    You can see by looking at the table below, that there are eleven possible outcomes. The dice can fall any of 36 ways. Six of these outcomes are called "doublets"--meaning both dice have the same number. The other 30 are variations. For example you can have an outcome of six by throwing 2-4, 4-2, and so on. All 36 possiblities need to be taken into account. This table shows the likleyhood of the various outcomes.
    Nick, Crap, or Point c c p p p N p p p N c
    The Throw 2 3 4 5 6 7 8 9 10 11 12
    Odds out of 36 throws 1 2 3 4 5 6 5 4 3 2 1


    You can calclulate the odds by adding up the fractions. Hitting a nick on the first time is equal to 8/36 in favor versus 28/36 against. This reduces down to 2/9 to 7/9, or as we say 7 to 2 against you scoring a nick.

    Now, what we are going to do is write a program that plays Craps. I'm going to give you some of the pieces of the program, and then have you put it all together. You may work with one partner if you wish. Here's the basics:

    Assignment
    Write a Program that plays raps with the user. Use the following guidelines:

    • you will need to four different functions. One to generate a random number, one to calculate the toss itself, one for winning, and one for losing. Let's look at these individually.

    • The random number function needs to include:
      unsigned seed = time(NULL);
      srand(seed);

      The purpose of this is to generate a random number based on the current time in seconds.

    • The toss function needs to include something like:

      int die1 = rand()/10%6 + 1;
      int die2 = rand()/10%6 + 1;
      int t=die1 + die2;
      cout<<"you tossed a " << t << endl;


      This modifies the rand() function to limit the random numbers to a range of 1 to 6 for each die.

    • Create two more functions: one to say you won, and one to say you lost
    • You will need to include three header files:
      iostream.h, stdlib.h, and time.h

    • Don't forget to create your function prototypes before your main function
    • Use the main function to call the other functions. Use if statements to determine if the user has won or lost. Good Luck! To help get you started, here is a sample of using the random number generator to roll the dice. [example]. Try running this example to study how the random numbers are created.