Author |
Message |
MossyMossy
|
Posted: Fri Oct 09, 2009 11:33 am Post subject: Getting Money back. |
|
|
If i was given a price of 35.46
and a person paid 40 dollars.
how can I get a total price, in how much change i have to give back
using mod, so for example I give.
4 dollar bill back. (in one dollar bills)
5 dimes
and 4 pennies. something like this, i cannot figure out how to make a program in turing with this |
|
|
|
|
|
Sponsor Sponsor
|
|
|
apomb
|
Posted: Fri Oct 09, 2009 12:15 pm Post subject: RE:Getting Money back. |
|
|
well for starters you forgot quarters, and secondly, you're on the right track with mod.
what do you have so far as far as turing code goes? |
|
|
|
|
|
Tony
|
Posted: Fri Oct 09, 2009 1:56 pm Post subject: RE:Getting Money back. |
|
|
You are in luck, as Canadian currency allows for a Greedy Algorithm to work. So you are taking the correct steps.
(Note that this method doesn't actually work for all currencies) |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
DtY
|
Posted: Fri Oct 09, 2009 3:26 pm Post subject: Re: RE:Getting Money back. |
|
|
Tony @ Fri Oct 09, 2009 1:56 pm wrote: You are in luck, as Canadian currency allows for a Greedy Algorithm to work. So you are taking the correct steps.
(Note that this method doesn't actually work for all currencies)
Really? Out of curiosity, what currencies wouldn't allow that? |
|
|
|
|
|
Tony
|
Posted: Fri Oct 09, 2009 3:51 pm Post subject: RE:Getting Money back. |
|
|
From the wikipedia page linked above
Quote:
Imagine the coin example with only 25-cent, 10-cent, and 4-cent coins. The greedy algorithm would not be able to make change for 41 cents, since after committing to use one 25-cent coin and one 10-cent coin it would be impossible to use 4-cent coins for the balance of 6 cents. Whereas a person or a more sophisticated algorithm could make change for 41 cents change with one 25-cent coin and four 4-cent coins.
I'm not sure of the real-world currency example; but pre-decimal British pound had fractions that were significantly different from our modern coin usage, which leads me to believe that there might be some obscure example that breaks the algorithm. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
MossyMossy
|
Posted: Fri Oct 09, 2009 6:26 pm Post subject: Re: Getting Money back. |
|
|
I just cant seem to get it right... |
|
|
|
|
|
tjmoore1993
|
Posted: Sat Oct 10, 2009 8:32 am Post subject: Re: Getting Money back. |
|
|
This works too...?
[mod edit]That did work well... too well... heck, it was a complete solution; not cool |
|
|
|
|
|
jbking
|
Posted: Sat Oct 10, 2009 12:47 pm Post subject: Re: Getting Money back. |
|
|
Here's just some ideas that I'll leave it to you to stitch together and make the code:
1. If you multiply any dollar amount by 100, you could use integers to represent the values.
2. You could apply a Greedy algorithm when it comes to making change if using Canadian or American currencies. The key point here is finding the largest denomination to use at any point in the process.
3. You may want to combine div and mod, as one would tell you the number of something and the other is how much left to make.
Hopefully that helps. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
tjmoore1993
|
Posted: Sat Oct 10, 2009 3:18 pm Post subject: RE:Getting Money back. |
|
|
WHAT DO YOU MEAN 2 WELL? I spent 1 minute on it for it to be removed :O!!!! |
|
|
|
|
|
Tony
|
Posted: Sat Oct 10, 2009 3:19 pm Post subject: RE:Getting Money back. |
|
|
remember -- don't post full solutions to school assignments. Pointers to tdocs are fine. Code samples are fine. Pseudo-code is fine. Doing work for them is not. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
tjmoore1993
|
Posted: Sat Oct 10, 2009 3:22 pm Post subject: RE:Getting Money back. |
|
|
Makes sense, I stopped programming with Turing for a while... I just used the basics!
I wonder if Fantastic Story is still alive XD! |
|
|
|
|
|
ecookman
|
Posted: Sat Oct 10, 2009 7:27 pm Post subject: Re: RE:Getting Money back. |
|
|
tjmoore1993 @ Sat Oct 10, 2009 3:22 pm wrote: Makes sense, I stopped programming with Turing for a while... I just used the basics!
I wonder if Fantastic Story is still alive XD!
lol I looked at FS a while ago |
|
|
|
|
|
|