Quote (Richter @ 29 Nov 2012 18:43)
"...to find all the ways..."
so if you enter the number 17.... what should be the output? think about it... you'll see that 17 already has a very huge amount of possibilities...
here are just a few:
Code
17-16-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1-0
17-12-11-10-9-8-7-6-5-4-3-2-1-0
17-16-11-10-9-8-7-6-5-4-3-2-1-0
17-16-15-10-9-8-7-6-5-4-3-2-1-0
...
17-16-15-14-13-12-11-10-9-8-7-6-5-0
...
17-12-11-10-5-0
17-16-11-10-5-0
17-7-6-5-4-3-2-1-0
17-16-6-5-4-3-2-1-0
17-7-2-1-0
17-16-11-1-0
17-12-2-1-0
17-12-11-6-5-0
...
think about the possibilities... are you really so crazy that you need all those numbers in the RIGHT ORDER? I at least still don't know what you want... I understand Irmi and I also understand you... but your way won't work until you know what recursive means :/
I guess that this output is what you want for the number 17:
17:
Code
1 1 5 5 5
1 1 5 10
1 1 1 1 1 1 1 10
1 1 1 1 1 1 1 5 5
1 1 1 1 1 1 1 1 1 1 1 1 5
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
or is it this version? (number of lines says how many possibilities, first row says how many cents, second one how many 5-cent pieces... and so on)
Code
2 3 0 0
2 1 1 0
7 0 1 0
7 2 0 0
12 1 0 0
17 0 0 0
or is the output just a "6 possibilities for the change are possible" ?
Order doesn't matter (thank god)
Also I'm not sure if this was obvious or not but I am coding in C at the moment if that makes a difference.
your short code block with all the 1's etc is what I am trying to get to at the moment.
I think my biggest problem right now is the act that my instructor gave me some starting hints and they just aren't working for me...let me know i you can explain them better?
Hints (not mandatory):
Here is the function description:
// Precondition: denomination = 1 (for penny), 2 (for nickel), 3 (for dime),
// or 4 (for quarter).
// Postcondition: If amount < 0, then 0 has been returned. Otherwise,
// the value returned is the number of ways that amount
// can be changed into coins whose denomination is no
// larger than denomination.
int ways (int amount, int denomination);
For the sake of simplifying the ways function, develop a coins function that returns the value of each
denomination. Thus, coins(1) returns 1, coins(2) returns 5, coins(3) returns 10, and coins(4) returns 25.
I understand recursion takes an input performs a reduction step and then calls itself using the result of that step ( on a very basic level) to some ending condition... at least that is what I think it means?
This post was edited by Nom_Nomz on Nov 29 2012 04:53pm