Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your job is to write a simple program that plays a dice game in C++ Ask the user to enter a seed value. Get a

Your job is to write a simple program that plays a dice game in C++ Ask the user to enter a seed value. Get a seed value from the user. If the user types a negative number, seed it with the system time otherwise use the user's seed. Dice Game Rules: The player rolls two standard 6-sided dice. These are the rules of a game:

  • Game play
    • If the first roll is 7 or 11, then the player win.
    • If the first roll is 2, 3 or 10, 12, then the player loses.
    • If the first roll is 4, 5, 6, 8, 9, that number becomes the target point.
      • At this point, the player continues to roll until he wins or loses.
      • If the player rolls the target point, he wins.
      • If the player rolls a 7, he loses.
      • If the player does not roll either the target or a 7, keep rolling using the current target.
  • Scoring and money
    • A player gets $9 when they win a game
    • A player loses $10 when they lose a game
    • A player gets $1 any time they roll a 7.

Game play requirements:

  • Display each die value rolled and total after each roll. For example: 3 and 5 for a value of 8
  • Display the target after the first roll if they don't win or lose.
  • Keep track of the player's score (wins and losses and money ) and display it after each game.
  • Print lines -------------------------------------- and the score after EACH game .
  • Do not roll the dice until the user types in the character 'r' . Pressing 'r' rolls the dice one time. Note that 'r' does not play an entire game.
  • If the user types 'q', display the current score and the dice game ends.

Utilize a function to get a roll. This function will need to be called twice (once for each of the dice).: int roll ( void ) { // code will generate a random number between 1 and 6 return number; }

Consider making your program modular by using functions

Hints: The random number function will produce the same sequence of random numbers for a given seed.

To make your numbers random every time you run the program, try initializing it only ONE time using the system time as the seed. Echo out all input. That is, if a user types in any input, print it back out. For example cout << "Enter r to roll "; cin >> letter; cout << letter;

When the user types in 'q', display a textual histogram of 50,000 dice rolls. Roll 50,000 times, count the number of 1's, 2's,3's, 4's, 5's, 6's of a single dice roll. In this section, DO NOT display the roll because it will flood the screen with output. Simply display the count for each roll after 50,000 rolls are complete.

------

Run your program using the seed 614 until you get 20 losses.

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

Students also viewed these Databases questions