Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Math problem

Author
Message
lancol
15
Years of Service
User Offline
Joined: 19th Apr 2009
Location:
Posted: 19th Apr 2009 18:14
Well, I'm having a problem with a change sorter thing I made a while ago. What it does is, it takes the input number (US dollars) and sorts it into the least amount of change possible; Quarters, dimes, nickels, pennies. I've run it a bunch of times, and every time, it leaves a remainder, and I don't know why. Be aware that it is heavy psuedo-code, (also if you know of a better way of doing it that would help)
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 19th Apr 2009 20:33
It's because dark basic only handles fractions to 7 decimal places, leaving an error of anything after that.

Try this instead, it uses all whole numbers, though the input is still in dollars.



lancol
15
Years of Service
User Offline
Joined: 19th Apr 2009
Location:
Posted: 19th Apr 2009 21:49
Well, I tried it out, but it didn't work the way I wanted exactly. But I think I know what you mean there, so hopefully I can figure somthing out with it. Thanks.
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Apr 2009 02:12
It's not absolutey necessary, but you could use the modulus command (in other languages its the operator %).
the modulus finds the remainder when you divide two numbers. so...
100 mod 25 = 0
because 25 fits into 100 evenly, and there is no remainder
101 mod 25 = 1
because 25 fits into 100 evenly, and then there is 1 left over.
124 mod 25 = 24
because 25 fits into 100 evenly, and then there are 24 left over.
125 mod 25 = 0
because 25 fits into 125 evenly!

So...
cents=1023
Heres some code

Login to post a reply

Server time is: 2024-11-25 08:32:15
Your offset time is: 2024-11-25 08:32:15