Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Code in C++, assignment begins at : In Dungeons & Dragons below the line: --------------------------------------------------------------------------------------------------- In Dungeons & Dragons and similar role-playing games, dice

Please Code in C++, assignment begins at : In "Dungeons & Dragons" below the line:

---------------------------------------------------------------------------------------------------

In "Dungeons & Dragons" and similar role-playing games, dice with different numbers of sides are used to determine the outcomes of events throughout the game.

There are different dice for different occasions: 4-sided, 6-, 8-, 10-, 12-, and 20-sided dice are common.

A required roll is typically designated d where is the number of dice to throw and is the number of sides on those dice. For example, 2d6 means throw two 6-sided dice and add the results, and 1d12 means throw one 12-sided die.

This lab requires you to write a program to read in such a designation, and then simulate throwing the appropriate dice, summing and displaying the result, three times in total.

NOTE: use the random number seed 1701, so that the test results will match when the program is implemented correctly.

We will simplify this a little by only dealing with 6, 10, 12 and 20 sided dice, and only allowing the user to specify 1-3 dice to be thrown.

For example, a program run might look like this:

Choose 1, 2, or 3 dice (6-, 10-, 12-, or 20-sided) Enter designation (e.g. '2d6'): 3d10 3d10 result: 8 + 9 + 9 = 26 3d10 result: 9 + 9 + 9 = 27 3d10 result: 5 + 1 + 9 = 15 

The input should be validated, so if the number of dice is not 1, 2, or 3, or if the middle character is not 'd', or if the number of sides is not6, 10, 12, or 20, the program should report the error:

Choose 1, 2, or 3 dice (6-, 10-, 12-, or 20-sided) Enter designation (e.g. '2d6'): 4x9 Not a valid designation 

Hints:

1) Read the number of dice into an integer variable.

2) Read in (consume) the d character.

3) Read the number of sides into an integer variable.

4) An N sided die should return results in the range 1..N.

5) You might want to review the documentation on rand().

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions