Question
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
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 able to input any positive value between 4 and 20 for the number of the sides on their dice, and you can assume that they 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.
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 1s. You should also keep track of how many times your roll came up with doubles along the way (but dont end the program until you roll snake eyes).
In addition, you will 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. Format this number to one decimal place.
How many sides on your dice (4-20)? -10 Sorry, that's not a valid number of sides. Please choose a positive number between 4 and 20. How many sides on your dice (4-20)? 30 Sorry, that's not a valid number of sides. Please choose a positive number between 4 and 20. How many sides on your dice (4-20)? 6 Ok, here we go . . . 1. The first die is 5 and the second die is 3 2. The first die is 2 and the second die is 2 3. The first die is 1 and the second die is 5 4. The first die is 6 and the second die is 1 . . . continue . . . 16. The first die is 1 and the second die is 1 You got snake eyes on try number 16! Along the way you rolled doubles 5 times. The average roll for the first die was: 2.9 The average roll for the second die was: 3.2
Note that the snake eyes roll that causes your loop to end should also count as a doubles roll.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started