
-----------------------------------
MossyMossy
Fri Oct 09, 2009 11:33 am

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

-----------------------------------
apomb
Fri Oct 09, 2009 12:15 pm

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
Fri Oct 09, 2009 1:56 pm

RE:Getting Money back.
-----------------------------------
You are in luck, as Canadian currency allows for a [url=http://en.wikipedia.org/wiki/Greedy_algorithm]Greedy Algorithm to work. So you are taking the correct steps.

(Note that this method doesn't actually work for all currencies)

-----------------------------------
DtY
Fri Oct 09, 2009 3:26 pm

Re: RE:Getting Money back.
-----------------------------------
You are in luck, as Canadian currency allows for a 
Really? Out of curiosity, what currencies wouldn't allow that?

-----------------------------------
Tony
Fri Oct 09, 2009 3:51 pm

RE:Getting Money back.
-----------------------------------
From the wikipedia page linked above

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.

-----------------------------------
MossyMossy
Fri Oct 09, 2009 6:26 pm

Re: Getting Money back.
-----------------------------------
I just cant seem to get it right...

-----------------------------------
tjmoore1993
Sat Oct 10, 2009 8:32 am

Re: Getting Money back.
-----------------------------------
This works too...?

[mod edit]That did work well... too well... heck, it was a complete solution; not cool

-----------------------------------
jbking
Sat Oct 10, 2009 12:47 pm

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.

-----------------------------------
tjmoore1993
Sat Oct 10, 2009 3:18 pm

RE:Getting Money back.
-----------------------------------
WHAT DO YOU MEAN 2 WELL? I spent 1 minute on it for it to be removed :O!!!!

-----------------------------------
Tony
Sat Oct 10, 2009 3:19 pm

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.

-----------------------------------
tjmoore1993
Sat Oct 10, 2009 3:22 pm

RE:Getting Money back.
-----------------------------------
Makes sense, I stopped programming with Turing for a while... I just used the basics! :D


I wonder if Fantastic Story is still alive XD!

-----------------------------------
ecookman
Sat Oct 10, 2009 7:27 pm

Re: RE:Getting Money back.
-----------------------------------
Makes sense, I stopped programming with Turing for a while... I just used the basics! :D


I wonder if Fantastic Story is still alive XD!

lol I looked at FS a while ago
