View Full Version : Making Change


domesticated om
12-19-05, 09:30 AM
I'm in the process of writing a program in visual basic that takes a Dollar amount, and converts it into breakdowns of change (quarters, nickels, pennies, etc).
I have already successfully created a code for tranlating specific dollar amounts into *one* type of change (IE- shows how many quarters/pennies/nickels it takes to equal the input amount rounded down). Now I want to make it show the amount of change using the least amount of coins.

Example-- If I input "$1.67", then it will produce a result of 1 dollar bill, 2 quarters (I'm not using 50 cent coins), a dime, a nickel, and 2 pennies.


MY question- any idea of how I would do this?

BTW- I'm not looking for help with VB, I just want to know iwhat potential equations would look like for doing this.

Thanks in advance.

fo3
12-19-05, 11:28 AM
first convert 1.67$ to 167 cents.
then divide 167 by 100 (results in 1,67) and round the answer down (results 1, as in 1 one dollar bill)
now subtract 1 times 100 from the 167 (results in 67)
then divide 67 by 25 (2,68) and round down (you get 2 quarters)
now subtract 2 times 25 from the 67 (17)
divide by 10 and round down
subtract again
divide by 5 and round down
etc.

You should probably just create a function that does all this and uses the rounded down values as variables for the number of dimes.

Zephyr
12-21-05, 02:48 PM
/ and mod. / and mod.