Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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 and
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!

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91976928
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As