Modify the code below to support specifying additional dice type in addition to a 6 sided...

70.2K

Verified Solution

Question

Programming

Modify the code below to support specifying additional dice typein addition to a 6 sided dice.

For example, the program could support six-sided, eight-sided,10 sided die.

HINTS: You will need to

  • Create an enum type for the dice type and values
  • Modify the parameter passing of some of the functions to passthe die type
  • Adjust the actual code that simulates the die roll to generatea range of values appropriate to the user's selected die type.

Think about parameter passing. It is possible to do this with avery few modifications to the program.

//Program: Roll dice

#include
#include
#include

using namespace std;

int rollDice(int num);

int main()
{
cout << \"The number of times the dice are rolled to \"
<< \"get the sum 10 = \" << rollDice(10) <cout << \"The number of times the dice are rolled to \"
<< \"get the sum 6 = \" << rollDice(6) << endl;

return 0;
}

int rollDice(int num)
{
int die1;
int die2;
int sum;
int rollCount = 0;

srand(time(0));

do
{
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
sum = die1 + die2;
rollCount++;
}
while (sum != num);

return rollCount;
}

Answer & Explanation Solved by verified expert
4.4 Ratings (780 Votes)
Thanks for the question Below is the code you will be needing Let me know if you have any    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students