Computer Science Canada Expressing a dollar amount as different coins. |
Author: | GDoughtUpInIt [ Wed Jul 14, 2004 12:22 pm ] |
Post subject: | Expressing a dollar amount as different coins. |
Hello everyone. I was wondering, how can I take a number such as $104.56 (or any other number) and express it as 5 twenty dollar bills, 4 loonies, 2 quarters, and 6 pennies? Any help will be GREATLY appreciated. Thank you. |
Author: | Tony [ Wed Jul 14, 2004 2:25 pm ] | ||
Post subject: | |||
wouldn't it be 2 toonies? ![]() anyways, what you do is :
|
Author: | rizzix [ Wed Jul 14, 2004 2:43 pm ] |
Post subject: | |
use modulus!! heh |
Author: | wtd [ Wed Jul 14, 2004 3:03 pm ] |
Post subject: | Re: Expressing a dollar amount as different coins. |
GDoughtUpInIt wrote: Hello everyone.
I was wondering, how can I take a number such as $104.56 (or any other number) and express it as 5 twenty dollar bills, 4 loonies, 2 quarters, and 6 pennies? Any help will be GREATLY appreciated. Thank you. Well, you should take toonies out too. ![]() |
Author: | wtd [ Wed Jul 14, 2004 3:09 pm ] | ||
Post subject: | |||
Note: Always use integers to represent dollars and cents, to avoid floating point inaccuracy. Anyway, at least the first few steps of this are going to look like:
|