-
Change money program
Hi
I want to write a program as described below:
How many ways exist in order to break a paper money into some of it's smaller coins.
for example we have one dollar as the paper money and the coins include 5, 10 and 50 cents.
any ideas how to start?
-
I would start by trying out some examples to see if I can find some pattern.
-
Well, you don't know how many different kinds of coins you'll have, and you don't know how much each type is worth, so you'll need a dynamically-sized array for that. Something like:
Code:
int numCoins;
int* coinAmounts;
Code:
coinAmounts = new int[i];
numCoins = i;
//Proceed with setting the values of each element of coinAmounts.
It's not obvious whether you're just having to run this for one dollar, or whether you have to run it for x dollars. You might need a variable for that too.
Basically you probably just want to take one dollar and think of how you can break it up in real life under American currency. Coins in that case are 1, 5, 10, 25, 50, and 100 cents. Practice that to some extent to get an idea for the algorithm and expand on it.
-
Is this a common assignment in code courses..? t pops up every now and then, in different forums and languages.
Dude, just google, diophantine equations.
-
This assignment is nothing more than basic math. You start with an int main()
Now, go and write the thing and if you really do end up needing help then post the code and errors here.