Well, as I often say, how would you do it on paper?

Let's say we're finding sums of 15, and we're part way through, and we have 2 at the start of the array.

In the recursive function we want to loop, but from what to what? 1..15? Would there be any point starting at 1 if we just want increasing sums? Would there be any point starting at 2 if we want to avoid duplicates? Once we've decided where we want to start counting from, how would we work that out?

What would be the upper limit? Remember from the output above, the sums starting with 2 are 2+3+4+6, 2+5+8 and 2+6+7.

Having decided on the loop, what now goes in the loop? We want to put the current number in the loop. How do we know what entry in the array to use? The first level would use [0], the second [1], the third [2], is there a pattern here that we could work out from something?

After assigning something to somewhere in the array, what next? Let's say we've got 2+3. Does this add up to 15? Do we want to print anything? Do we want to recurse deeper? What about when we get to 2+13 (just realised that's missing from my output above - bug fixed). Same three questions. Would it be appropriate to use an if/else here? What would the test be? What would we do (a) if that test is true; (b) if that test is false?

Corrected output for 15:

Enter a number: 15

1+2+3+4+5

1+2+3+9

1+2+4+8

1+2+5+7

1+2+12

1+3+4+7

1+3+5+6

1+3+11

1+4+10

1+5+9

1+6+8

1+14

2+3+4+6

2+3+10

2+4+9

2+5+8

2+6+7

2+13

3+4+8

3+5+7

3+12

4+5+6

4+11

5+10

6+9

7+8

Let's say we're finding sums of 15, and we're part way through, and we have 2 at the start of the array.

In the recursive function we want to loop, but from what to what? 1..15? Would there be any point starting at 1 if we just want increasing sums? Would there be any point starting at 2 if we want to avoid duplicates? Once we've decided where we want to start counting from, how would we work that out?

What would be the upper limit? Remember from the output above, the sums starting with 2 are 2+3+4+6, 2+5+8 and 2+6+7.

Having decided on the loop, what now goes in the loop? We want to put the current number in the loop. How do we know what entry in the array to use? The first level would use [0], the second [1], the third [2], is there a pattern here that we could work out from something?

After assigning something to somewhere in the array, what next? Let's say we've got 2+3. Does this add up to 15? Do we want to print anything? Do we want to recurse deeper? What about when we get to 2+13 (just realised that's missing from my output above - bug fixed). Same three questions. Would it be appropriate to use an if/else here? What would the test be? What would we do (a) if that test is true; (b) if that test is false?

Corrected output for 15:

Enter a number: 15

1+2+3+4+5

1+2+3+9

1+2+4+8

1+2+5+7

1+2+12

1+3+4+7

1+3+5+6

1+3+11

1+4+10

1+5+9

1+6+8

1+14

2+3+4+6

2+3+10

2+4+9

2+5+8

2+6+7

2+13

3+4+8

3+5+7

3+12

4+5+6

4+11

5+10

6+9

7+8