i was working on a small program to find how many ways you can break a dollar. i was able to code a simple version that randomly chooses a coin value from an array and add up to a dollar while keeping count of the coins used. How do i run this code to find all possible combinations?
I am new and as you can see from my code i am not sure how to run thru and output all possibility.
Alas, while the answer could technically be found by simulation, you are better off handling it differently.
Consider all (USD, sorry) coins ≤ $1:
• dollar coin
• half-dollar
• quarter
• dime
• nickel
• penny
Here is the next question to ask: does order matter?
For dollar questions the answer is typically “no”. This answer will assume that. (If it is not, then the answer is similar, but you cannot discount branches like we do here.)
A dollar-coin is one way to make a dollar, with no coinage left over. N = 1.
A half-dollar coin makes half a dollar. How many ways can I use coins to make half a dollar?
N += (number of ways to make a half dollar).
Three quarters make 75 cents. How many ways can I use coins to make a quarter?
N += (number of ways to make a quarter)
I think so, just coding wise is were I'm lost. Would this be a multi demential array? We're the columns would hold the coin counts and the rows would hold the coin values?