outputing change in denominations
Author |
Message |
rated
|
Posted: Wed Sep 24, 2008 5:08 pm Post subject: outputing change in denominations |
|
|
Hi, I have to write a program that will output a receipt showing purchased price, taxes, total, amount paid and change. I did that part.
But what do I have to do so that my program will output the change in denominations (e.g. change is $8.04 - output exact dominations, that is to say, one $5 bill, a toonie, quarters.etc)?
How do I do that using the modulus %operator?
thanks!. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Wed Sep 24, 2008 6:22 pm Post subject: RE:outputing change in denominations |
|
|
I did this last year. It was pretty complicated. Basically, you find the greatest denomination the total can divide into, use div to find out how many of those bills/coins are needed, then subtract that number times the bill value to get your remainder (you can't use mod here). Then repeat. Very long project. |
|
|
|
|
|
gitoxa
|
Posted: Wed Sep 24, 2008 9:40 pm Post subject: RE:outputing change in denominations |
|
|
You can use modulus to tell you right away how much is left.
For example, says you have $8.32
Biggest money denomination would be a 5 dollar bill.
8.32 mod 5 = 3.32 |
|
|
|
|
|
|
|