Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ language, We will implement a game of Craps (with simplified rules), and use pointers to the integers rather than passing them in by

In C++ language,

We will implement a game of Craps (with simplified rules), and use pointers to the integers rather than passing them in by value, so that they arent included in the print statements.

Rules:

  • The player rolls two dice
  • A win is a total of 7 or 11
  • A loss is 2, 3 or 12
  • Any other total is ignored

You will write a procedure called roll() that is of type void. It receives the memory location of an integer variable, and it modifies that value to be a random integer between 1 and 6 (remember how to do this from our guessing game in CSCI 155). Thus, the function calls are simply:

roll(&roll1); //Both are void roll(&roll2);

Note that since it takes the memory locations, it will alter their values even though roll() contains no return statement. Specifically, this call will set the integer values roll1 and roll2 each to a random dice roll between 1 and 6 without passing the number back to main. The value is placed directly into the memory locations &roll1 and &roll2. These numbers are added together in main() to determine the total for use in scoring.

The main procedure, after roll has been called on your two dice variables, will print out the results of the rolls, give your total, and evaluate the win/lose conditions. You also have a bank that starts you with $100 and allows you to bet on your next roll with 1:1 odds (whatever amount of money you bet you either win or lose) until you enter n at the main menu.

Sample output:

Welcome to the CRAPS game.

You have $100. Do you want to roll (y/n)? y

How much do you want to bet? 20

You rolled a 3 and a 4. Your total is 7. You win!

You have $120. Do you want to roll (y/n)? y

How much do you want to bet? 10

You rolled a 3 and a 5. Your total is 8.

You have $120. Do you want to roll (y/n)? y

How much do you want to bet? 10

You rolled a 1 and a 1. Your total is 2. You lose!

You have $110. Do you want to roll (y/n)? n

Thank you for playing.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

What are some facilitating conditions for employee empowerment?

Answered: 1 week ago

Question

LO1 Identify why performance management is necessary.

Answered: 1 week ago