So just to clarify:
The purpose of this program is to iterate (or recurse rather) through all the possibilities of rolling 3 dice, and to print out the payoff for each combo? So you would be looking at a list of values for the dice like:
Code:
1, 1, 1
1, 1, 2
1, 1, 3
1, 2, 1
1, 2, 2
1, 2, 3
1, 3, 1
1, 3, 2
1, 3, 3
2, 1, 1
2, 1, 2
2, 1, 3
2, 2, 1
2, 2, 2
2, 2, 3
2, 3, 1
2, 3, 2
2, 3, 3
3, 1, 1
3, 1, 2
3, 1, 3
3, 2, 1
3, 2, 2
3, 2, 3
3, 3, 1
3, 3, 2
3, 3, 3
If that's the case, then I will start you off with the following shell of a program I used to generate that list, leaving the juicy recursive logic for you.
Code:
#define DIE_MAX 3 // each die can have values of 1, 2 or 3
void recurse_dice(int d1, int d2, int d3)
{
printf("%d, %d, %d\n", d1, d2, d3);
// recursive calls/logic goes here
}
int main(void)
{
recurse_dice(1, 1, 1); // start with each die having a value of 1
return 0; // you correctly declared main to return an int, now return one -- 0 means success
}
It's a basic backtracking problem, meaning when you "reach the end" of one path, you back up a step and "try the next path". As a hint, notice that, in the list above, when d3 reaches the max, you reset it to 1 and increase d2 by 1. Similarly, when d2 reaches the max (and d3 has reached the max), you reset them both to 1 and increase d1. Finally, when all 3 have reached the max, you are done.
Start with adding the logic (a simple if statement) just to iterate through values of d3 (with d1 and d2 fixed at 1), to produce the output
Code:
1, 1, 1
1, 1, 2
1, 1, 3
Then extend that (adding another if statement) to iterate through all combinations of d2 and d3, with d1 fixed at 1. Then add the last bit to iterate through all 3 dice.