Re: Help!!! Making Change
You have not indicated what is your problem here. However I think there is a problem with your logic. I think you always get "one way" as the result. If that the problem or other please put it here.
Re: Help!!! Making Change
Yes, the problem is that i keep only getting one way. How do i make it so i get alll different ways?
Re: Help!!! Making Change
Ok. Your logic should be changed. Actually by now you are getting the best way. Now what you have to do is,
1. count how many 2.0 s, 1.0 s, 0.25s, 0.05 and 0.01s in your best way.
for ex: 5.53 will give 2 for 2.0s, 1 for 1.0s 0 for 0.25s 2 for 0.05s and 3 for 0.01s.
2. Now write these methods
i.) Change2s - This should find all the ways that other values can represent 2.0
also you can assign it to a constant because it's always the same. Say this is w. As the count of 2.0s is 2 in my ex. w should be multiplied by factorial of 2.0s count(i.e. 2!=2*1) . This will result how many ways to represent 2.0 count.
ii) Change1s- This should find all the ways that other values (except 2.0) can represent 1.0. This also a constant. You should do the same as in i.)
...
...
Sum of all these 4 methods +1 will give you the correct result.
Re: Help!!! Making Change
my main concern is there any mathematical way at gettin at how many ways its possible, i.e. like factorials or somthing?
Re: Help!!! Making Change
Quote:
Originally Posted by needhelp1234
my main concern is there any mathematical way at gettin at how many ways its possible, i.e. like factorials or somthing?
Yes, certainly,. I think already I've described it.
Say you have a method to find factorial of an integer
TotalWays=(fact(countof2.0s)*(No.of ways to make 2.0))+(fact(Countof1.0)*(No.of ways to make1.0)) + (fact(Countof 0.25)*(No.of ways to make0.25)) + (fact(Countof0.05)*(No.of ways to make0.05))+ (fact(Countof0.01)*(No.of ways to make0.01))
Is the equation.
You may have difficulty to find No.of ways to make "SomeValue"
I'll describe
As the 0.01 is the smallest unit you have only one way to make 0.01
As the 0.05 is the next smaller, you have only two ways to make 0.05
i.e. 1*0.05 or 5* 0.01
As the 0.25 has two smaller units, you can make it in following ways
i.) 1*0.25 or 5*0.05 or (4*0.05 And 5*0.01) or (3*0.05 And 10*0.01) or...or (25*0.01)
i.e Therefore there are 7 ways
Then 1.00 has three smaller units. You can make it in following ways
i) 1*1.00 or 4*0.25 or (3*0.25 And rest 0.25 in above 7 ways) or (2*0.25 And rest 0.50 in above 7 ways)....
i.e therefore there are 24 ways
In this way you can build some model. And try to go through
Re: Help!!! Making Change
I'm sorry, Your code is not so bad. It gives a result which is correct to some extend. I'll give you a good code if I could find some time to do it. And also I didn't see that you have another value of 0.1
Re: Help!!! Making Change
Thanks, a bunch. Sri Lankan eh, that makes 2 of us. But yeah im in class working on it ill post what i get at the end of class. Thanks for helping me out. It's due tomorrow so I'll try to get the best code I can.
K This is what I dont know exactly how to do. I know how to individually get the ways with each coin but now how can i make a function that calculates the total amount of ways we can make change using all the coins not just one at a time. So two coins, 3, 4, etc at a time. Remember: I want to find the amount of ways to find change not which coins to use.
Example : 0.05 has 2 ways 1 nickle 5 pennies...etc
0.1 has 4 ways, 1 dime, 2 nickles, 1 nickle 5 pennies, 10 pennies
Re: Help!!! Making Change
so yeah we tried and tried and were down to my last 2 housr before i sleep, and i am sooo lost and its due tomorrow oh my goodness. There were 5 programs i got all 4 and this ones givng me too much trouble...help!
Re: Help!!! Making Change
what info do you have at the begining? Take a look on "Function Choose" in the"Unique Combinations" in my signature. It mitht help.
Re: Help!!! Making Change
how can i use ur unique comibnations, recursively im startin to see how i can use it buh styll kinda blurry
Re: Help!!! Making Change
The function "Choose" in the class works this way: let say there are 4 players and we want to know how many unique selection of two players we can have; whis wold be 6 combinations. Now I am not sure why you need to have any recursive calls to a function. If you want to call the function recursively then there should be conditions that would end the recursive calls. What condition would that be?
Re: Help!!! Making Change
the assignment is to get it recursively but i have no clue this is the "challenge assignment"