logo CodeStepByStep logo

diceRolls

Language/Type: C++ backtracking recursion

Write a recursive function named diceRolls accepts an integer representing a number of 6-sided dice to roll, and output all possible combinations of values that could appear on the dice. For example, the call of diceRolls(3); should print:

{1, 1, 1}
{1, 1, 2}
{1, 1, 3}
{1, 1, 4}
{1, 1, 5}
{1, 1, 6}
{1, 2, 1}
{1, 2, 2}
   ...
{6, 6, 4}
{6, 6, 5}
{6, 6, 6}

If the number of digits passed is 0 or negative, print no output. Your function must use recursion, but you can use a single for loop if necessary.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.