Question: PLEASE USE C++ LANGUAGE AND GIVE CPP FILE SOURCE CODE AND LINE DOC EXPLAINING WHAT IS HAPPENING Overview For this assignment, write a program that

PLEASE USE C++ LANGUAGE AND GIVE CPP FILE SOURCE CODE AND LINE DOC EXPLAINING WHAT IS HAPPENING

Overview

For this assignment, write a program that will simulate a single game of Craps.

Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, 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, or 12, 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 rolling the dice until they either roll a sum that equals the point or they roll a 7. If the player "makes their point," they win. If they roll a 7, they lose.

Random Number Generation

In the first three programs, the user has been asked for input. This program will be different. Rather than asking the user what the result of each roll of the dice, the random number generator will be used to "roll" the dice.

To use the random number generator, first add a #include statement for the cstdlib library to the top of the program:

#include

Next, initialize the random number generator. This is done by calling the srand function and passing in an integer value (known as a seed value). This should only be done ONE time and it MUST be done before actually getting a random number. A value of 1 (or any integer literal) will generate the same sequence of "random" numbers every time the program is executed. This can be useful for debugging:

srand(1);

To get a different series of random numbers each time the program is run, the actual time that the program is run can be passed as the seed value for the random number generator. This is done as follows:

srand(time(0));

If the time function is used, an extra #include statement for the ctime library must be added to the top of the program.

Finally, generate a random number by calling the rand function:

num = rand();

The above line of C++ code will generate a "random" integer between 0 and RAND_MAX and save the value in an integer variable named num. RAND_MAX is a pre-defined constant that is equal to the maximum possible random number. It is implementation dependent but is guaranteed to be at least 32,767.

Modulus division can be used to restrict the "random" integer to a smaller range:

num = rand() % 7;

will produce a value between 0 and 6. To change the range to 1 through 7, simply add 1:

num = rand() % 7 + 1;

To get random values that are within a specified range that starts at a value other than 0 or 1:

num = minimum_value + (rand() % (maximum_value - minimum_value + 1));

So, to get values within the range 3 - 17:

num = 3 + (rand() % (17 - 3 + 1));

Basic Program Logic

Seed the random number generator with a value of 22. Note: other seed values may be used to produce different results. However, the version that is handed in for grading MUST use a seed value of 22.

Next, roll the dice by generating two random numbers between 1 and 6. The two numbers should be added together and then displayed along with the sum.

If the sum of the dice is equal to 7 or 11, the game is over and the player has won. Display a congratulatory message.

If the sum of the die is equal to 2, 3, or 12, the game is over and the player has lost. Display a message indicating the player has lost because they rolled craps.

For any other sum, the sum is now the point and the game should continue until the user rolls the point again or rolls a 7. To do this:

Save the sum (the point) in a variable so it can be used for a later comparison

Display the point

Create a variable and initialize it to a value of your choice to indicate that the game should continue.

In a loop that should execute as long as the game should continue:

roll the die and display the two values along with the sum

if the sum of the die is the same as the point, display a congratulatory message indicating the player has made their point and they won the game. Also change the variable that controls the loop to indicate the game should no longer continue.

otherwise, if the sum of the die is 7, display a message that the player has lost the game and change the variable that controls the loop to indicate the game should no longer continue.

Symbolic Constants

The program MUST use at least three symbolic constants. Some options are:

an integer for each of the values (2, 3, and 12) that represents craps on the first roll of the die

an integer that represents the value 7

an integer that represents the value 11

Program Requirements

Make sure to actually use the symbolic constants that are created.

Be sure to #include

Make sure that the copy of the program that is handed in uses srand(22); to set the seed value for the random number generator.

Output

Some runs of the program follow. Each one is marked with the srand value that produced the result.

Run 1 using srand(10);

Player rolled: 6 + 4 = 10

The point is 10

Player rolled: 3 + 3 = 6

Player rolled: 6 + 3 = 9

Player rolled: 3 + 1 = 4

Player rolled: 3 + 4 = 7

You seven'd out and lost!

Run 2 using srand(7);

Player rolled: 2 + 5 = 7

You won!

Run 3 using srand(22);

Player rolled: 3 + 1 = 4

The point is 4

Player rolled: 5 + 1 = 6

Player rolled: 4 + 4 = 8

Player rolled: 6 + 6 = 12

Player rolled: 4 + 4 = 8

Player rolled: 2 + 1 = 3

Player rolled: 5 + 1 = 6

Player rolled: 2 + 4 = 6

Player rolled: 3 + 5 = 8

Player rolled: 5 + 3 = 8

Player rolled: 2 + 1 = 3

Player rolled: 2 + 2 = 4

You rolled your point! You won!

Run 4 using srand(1);

Player rolled: 6 + 6 = 12

Craps! You lost!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!