Write a program that will simulate a single game of craps

Assignment Help C/C++ Programming
Reference no: EM131220986

C++ program code

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 die 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 die is equal to 7 or 11, the player wins immediately. If the sum of the first roll of the die is equal to 2, 3, or 12, the player has rolled "craps" and loses immediately. If the sum of the first roll of the die 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 die 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.

Processing

The program will use the random number generator to simulate the rolling of the die. Therefore, the random number generator must be seeded. This is done one time in the program. Use srand(time(0)).

Next, roll the die 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 die 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.

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:

o roll the die and display the two values along with the sum
o 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.
o 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 should 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

Processing Requirements

1. Make and use meaningful variable names.
2. Make sure to actually use the symbolic constants that are created.
3. Be sure to #include <cstdlib> and <ctime>
4. The program MUST be fully documented according to the documentation standards on the course website. Include line documentation. There is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does.
5. Hand in a copy of the source code (CPP file) using Blackboard.

Output

Some runs of the program follow. Your results probably won't match these exactly because of the use of the time when seeding the random number generator.

Run 1

Player rolled: 1 + 6 = 7

You won!

Run 2

Player rolled: 2 + 3 = 5

The point is 5

Player rolled: 4 + 2 = 6
Player rolled: 6 + 5 = 11
Player rolled: 6 + 6 = 12
Player rolled: 6 + 4 = 10
Player rolled: 6 + 6 = 12
Player rolled: 6 + 1 = 7

You seven'd out and lost!

Run 3

Player rolled: 1 + 4 = 5

The point is 5

Player rolled: 5 + 3 = 8
Player rolled: 4 + 4 = 8
Player rolled: 1 + 1 = 2
Player rolled: 1 + 2 = 3
Player rolled: 3 + 3 = 6
Player rolled: 6 + 5 = 11
Player rolled: 5 + 6 = 11
Player rolled: 6 + 5 = 11
Player rolled: 5 + 6 = 11
Player rolled: 6 + 3 = 9
Player rolled: 6 + 4 = 10
Player rolled: 3 + 5 = 8
Player rolled: 6 + 4 = 10
Player rolled: 4 + 2 = 6
Player rolled: 6 + 3 = 9
Player rolled: 3 + 5 = 8
Player rolled: 5 + 4 = 9
Player rolled: 2 + 1 = 3
Player rolled: 1 + 1 = 2
Player rolled: 2 + 2 = 4
Player rolled: 5 + 3 = 8
Player rolled: 1 + 3 = 4
Player rolled: 2 + 2 = 4
Player rolled: 3 + 1 = 4
Player rolled: 1 + 4 = 5

You rolled your point! You won!

Run 4

Player rolled: 2 + 2 = 4

The point is 4

Player rolled: 4 + 5 = 9
Player rolled: 5 + 1 = 6
Player rolled: 1 + 2 = 3
Player rolled: 2 + 3 = 5
Player rolled: 1 + 2 = 3
Player rolled: 3 + 5 = 8
Player rolled: 2 + 4 = 6
Player rolled: 6 + 3 = 9
Player rolled: 6 + 2 = 8
Player rolled: 3 + 4 = 7

You seven'd out and lost!

Reference no: EM131220986

Questions Cloud

What does the policy say about accountability : Are there any flaws in the policy? In your opinion, could this policy be ACA or CALEA accredited? What does the policy say about accountability?
Instructions and data found in textbook : For this assignment, you will be using the instructions and data found in your textbook at the end of Chapter 15, "Data Preparation and Description," in Question 3, which describes an inventory challenge facing many shoe retailers. This is listed ..
Find the x and y coordinates of both points of intersection : You are given a circle with radius 5 centered at x = 1, y = 2. You want to calculate the intersection of some lines with that circle. Write a MATLAB script to find the x and y coordinates of both points of intersection. You should test this code a..
Understanding decision making : As we work on understanding decision making, and interpersonal and group behavior, let us focus this week's discussion on the Health Care System.
Write a program that will simulate a single game of craps : Write a program that will simulate a single game of Craps. Craps is a game of chance where a player will roll 2 six-sided dice. The sum of the die will determine whether the player wins immediately, loses immediately, or if the game continues.
Does acquisition benefit the stockholders of melvins bank : Does this acquisition benefit the stockholders of Melvin's Bank? - Does the answer depend on the motives for the purchase? Explain.
What are the four purposes of research : Things we know from direct experience are a direct result of which type of reality? Things we consider real because we've been told they are real are which type of reality?
Spiritual and moral dimensions : Can servant leadership exist without spiritual and moral dimensions? Explain your response.
How long it takes to fill the glass to the brim : A glass has the shape of a truncated cone of height 5 inches. Its top diameter is 3.5 inches and its base diameter is 2 inches. If water is poured into the glass at 2 gallons per minute, write a script to calculate how long it takes to fill the gl..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Checking for a palindrome

For this Programming Activity, you will write a GUI-based program checking for a Palindrome.Turn to Page 959 in your text.Complete Programming Activity 1: Checking for a Palindrome.

  Economy of kenya has a budget deficit

The economy of Kenya has a budget deficit of KSH 500B. This deficit is likely to be funded through domestic borrowing and taxation. Using an appropriate model, explain the macroeconomic implications of such a move.

  Calculate the component voltages

Calculate the component voltages for the following series resonant RLC circuit

  Write a program to calculate the volume flow rate in cubic

write a program to calculate the volume flow rate in cubic feet per second of water flowing through a pipe of diameter

  Program that presents a menu of choices for the user

Write a C program that initially presents a menu of choices for the user.

  A computational study of a spring-mass system in steady

a computational study of a spring-mass system in steady stateidealized spring-mass systems have numerous applications

  Farey fractions of level one

Write a program that for a number n entered by the user creates-by constantly extending it-a linked list of fractions at level n and then displays them.

  Write a matrix multiplication program

Write a C++, matrix multiplication program which you can instrument to monitor and measure execution time as a function of problem size. Make sure it works in Microsoft Visual Studio.

  Create an array of customer names

In preparation for more complex data processing tasks using object-oriented objects that you will create in up-coming units, in this unit you will utilize arrays to build some basic processing logic and structures.

  Using which of the following techniques in c++

Using which of the following techniques in C++ is it possible to have different functions with the same name?select all that apply

  A stack is referred to as a last-in first-out

This lab, along with your TA, will help you navigate through designing, implementing, and testing a dynamic stack. Recall, a stack data structure is a restricted linked list, where only the top node in the stack may be accessed at any given time

  Calculate the cost of carrying additional luggage

The application used to calculate the cost of carrying additional luggage results in erroneous amount, if the weight of the luggage is a fractional number. Help the development team modify the code snippet so that the cost of carrying additional lu..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd