Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program which first prompts the user for the number of sides to the dice they will be rolling. Your user should be limited

Write a program which first prompts the user for the number of sides to the dice they will be rolling. Your user should be limited to selecting dice with the following number of sides:

4 sides

6 sides

8 sides

10 sides

12 sides

20 sides

You can assume that that your user will enter integers when prompted. You will need to validate their input before you continue (i.e. entering -10 should cause your program to tell the user that their input is invalid). You should re-prompt the user to enter a value if they supply bad data. Hint: use a "while" loop to keep the user "trapped" until they supply you with "good" data.

Next, your program should keep "rolling the dice" until the program generates a "snake eyes" roll (1 and 1). This means that you will roll two virtual dice of the specified size at a time. The program should "announce" every pair rolled and then tell the user how many rolls were required to get a pair of ones. You should also keep track of how many times your roll came up with "doubles" along the way (but you shouldn't end the program until you roll "snake eyes"). You also will need to keep track of how many times a High / Low combination has been rolled. A High / Low combination means that one dice rolled a 1 and the other rolled the highest possible value. For example, with two 6 sided dice a High / Low combination would be 1 and 6. For 10 sided dice it would be 1 and 10.

In addition, you will want to calculate the average roll for each dice and present this information to the user. See the sample output below to see what this should look like. You should format this number to two decimal places. Note that the "snake eyes" roll that causes your loop to end should also count as a "doubles" roll. Here's a sample running of the program :

How many sides on your dice (4, 6, 8, 10, 12 or 20)? -10

Invalid size, try again

How many sides on your dice (4, 6, 8, 10, 12 or 20)? 3

Invalid size, try again

How many sides on your dice (4, 6, 8, 10, 12 or 20)? 6

Thanks, here we go!

dice number 1 is 4 and dice number 2 is 6 dice number 1 is 1 and dice number 2 is 5 dice number 1 is 2 and dice number 2 is 1 dice number 1 is 5 and dice number 2 is 2 dice number 1 is 3 and dice number 2 is 2 dice number 1 is 6 and dice number 2 is 1 - High / Low! dice number 1 is 3 and dice number 2 is 3 - Doubles! dice number 1 is 3 and dice number 2 is 6 dice number 1 is 3 and dice number 2 is 2 dice number 1 is 5 and dice number 2 is 5 - Doubles! dice number 1 is 3 and dice number 2 is 4 dice number 1 is 3 and dice number 2 is 4 dice number 1 is 2 and dice number 2 is 1 dice number 1 is 5 and dice number 2 is 5 - Doubles! dice number 1 is 1 and dice number 2 is 3 dice number 1 is 1 and dice number 2 is 1 - Snake eyes!

You got snake eyes! Finally! On try number 16

Along the way you rolled doubles 4 times. (25.00% of all rolls were doubles)

Along the way you rolled high/low 1 times. (6.25% of all rolls were high/low)

Average roll for dice #1 was 3.12

Average roll for dice #2 was 3.19

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

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions