Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Roll the Dice In games with two dice (such as Monopoly), rolling two 6-sided dice and getting the same side or number on both

image text in transcribedimage text in transcribed

2. Roll the Dice In games with two dice (such as Monopoly), rolling two 6-sided dice and getting the same side or number on both dice is called "doubles" i.e. the first die rolls a 5 and the second die rolls a 5 at the same time). One special type of "doubles" roll is called "snake eyes," which is rolling two l's at the same time. The most common size of dice used in games today is the 6-sided dice, but there are plenty of other sizes available. For example, popular role-playing games such as Dungeons and Dragons use dice with a variety of sizes, such as 4, 12 and 20 sided dice. For this assignment you will be writing 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 it gets snake eyes. 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") In addition, you will want to calculate the average roll for each die and present this information to the user. See the sample program below to see what this should look like. You should format this number to two decimal places. # Sample input: How many sides on your dice (4, 6, 8, 10, 12 or 20) ? -10 2 # Sample input: How many sides on your dice (4, 6, 8, 10, 12 or 20) ? -10 Sorry, that's not a valid size. How many sides on your dice (4, 6, 8, 10, 12 or 20)? 6 Thanks! Here we go ... 9 10 11 12 # Sample output: 1. die number 1 is 5 and die number 2 is 3. 2. die number 1 is 2 and die number 2 is 2. 3. die number 1 is 1 and die number 2 is 5. 4. die number 1 is 5 and die number 2 is 1. ... continue ... 16. die number 1 is 1 and die number 2 is 1. 15 You got snake eyes! Finally! On try number 16! Along the way you rolled doubles 5 times (31.25% of all rolls were doubles) The average roll for die #1 was 2.95 The average roll for die #2 was 3.20

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

Domain Transfer Learning With 3q Data Processing

Authors: Ahmed Atif Hussain

1st Edition

B0CQS1NSHF, 979-8869061805

More Books

Students also viewed these Databases questions