Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 1'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.

Some multi-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. The 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 the 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 tell the user if the roll qualifies as one of the following. Note that some rolls may be classified twice (i.e. 'snake eyes' also counts as a 'doubles' roll):

  • A 'high' roll (i.e. on a six sided die, (6 and 6) )
  • A 'high/low; roll (i.e. on a six sided die, (1 and 6) or (6 and 1)
  • An 'even; roll (i.e. both die values are even: (2 and 2), (4 and 4))
  • An 'odd' roll (i.e. both die values are odd: (3 and 3), (5 and 5))
  • A 'mixed' roll (i.e. one even value and one odd value: (2 and 5), (1 and 6))
  • A 'sum value' (i.e. adding both die values together equals the size of the current die
  • A 'neighbor' roll (i.e. the values are directly adjacent: (1 and 2), (3 and 4))
  • A 'middle' roll (i.e. the values in the direct middle of the range of possible values: (on a 4 sided die this would be (2,3) or (3,2); on a 6 sided die this would be (3,4) or (4,3); on an 8 sided die this would be (4,5) or (5,4), etc.)
  • A 'double' roll (i.e. (2 and 2), (4 and 4), (6 and 6))
  • 'Snake Eyes' (1 and 1) - this should end the rolling portion of the program

At the end of the game 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. Here's a sample running of the program (user input is shaded in yellow for your reference - you do not need to code your program to generate color):

How many sides on your dice (4, 6, 8, 10, 12 or 20)? 1 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)? -5 Invalid size, try again. How many sides on your dice (4, 6, 8, 10, 12 or 20)? 6 Thanks, here we go! 1. die roll is *3* and *1* Odd! 2. die roll is *4* and *1* Mixed! 3. die roll is *6* and *1* High / Low! Mixed! 4. die roll is *3* and *3* Odd! Sum Value! Doubles! 5. die roll is *3* and *5* Odd! 6. die roll is *2* and *5* Mixed! 7. die roll is *2* and *2* Even! Doubles! 8. die roll is *3* and *6* Mixed! 9. die roll is *5* and *6* Mixed! Neighbor! 10. die roll is *4* and *2* Even! Sum Value! 11. die roll is *5* and *3* Odd! 12. die roll is *1* and *2* Mixed! Neighbor! 13. die roll is *2* and *1* Mixed! Neighbor! 14. die roll is *5* and *6* Mixed! Neighbor! 15. die roll is *1* and *3* Odd! 16. die roll is *1* and *3* Odd! 17. die roll is *3* and *6* Mixed! 18. die roll is *1* and *5* Odd! Sum Value! 19. die roll is *3* and *2* Mixed! Neighbor! 20. die roll is *5* and *2* Mixed! 21. die roll is *2* and *2* Even! Doubles! 22. die roll is *1* and *5* Odd! Sum Value! 23. die roll is *1* and *4* Mixed! 24. die roll is *1* and *3* Odd! 25. die roll is *3* and *1* Odd! 26. die roll is *5* and *3* Odd! 27. die roll is *2* and *6* Even! 28. die roll is *4* and *6* Even! 29. die roll is *1* and *4* Mixed! 30. die roll is *3* and *4* Mixed! Neighbor! Middle! 31. die roll is *1* and *1* Odd! Doubles! Snake Eyes! You finally got snake eyes on roll #31 Along the way you rolled HIGH 0 time(s). (0.00% of all rolls) Along the way you rolled HIGH / LOW 1 time(s). (3.23% of all rolls) Along the way you rolled EVEN 5 time(s). (16.13% of all rolls) Along the way you rolled ODD 12 time(s). (38.71% of all rolls) Along the way you rolled MIXED 14 time(s). (45.16% of all rolls) Along the way you rolled SUM VALUE 4 time(s). (12.90% of all rolls) Along the way you rolled NEIGHBOR 6 time(s). (19.35% of all rolls) Along the way you rolled MIDDLE 1 time(s). (3.23% of all rolls) Along the way you rolled DOUBLE 4 time(s). (12.90% of all rolls) Along the way you rolled SNAKE EYES 1 time. (3.23% of all rolls) Average roll for die #1: 2.77 Average roll for die #2: 3.35

Note that the "snake eyes" roll that causes your loop to end should also count as a "doubles" roll. You should ensure that your program produces the same output as the programs above, including the order of the labels (use the list of "roll types" above and check each type in order)

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

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

Students also viewed these Databases questions

Question

6. Conduct an implementation study of mini/focus lesson.

Answered: 1 week ago

Question

1. Why do you think that most people treat email so casually?

Answered: 1 week ago