English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am so confuse how to code this.
what ever the total change is lets say $2.78 have to make it come out to be how many dollars, quarters, dime, nickels , penny.

but i just dont know how to use the Mod operator to do it.
this is is wat i did so far.
but it dont work gives me a error if i have something like
change mod .25 ... error is division by zero. and it wont work. wats wrong?

curDollars = curTotalChange \ 1
intRemainder1 = curTotalChange Mod 1

intQuarters = intRemainder1 / 0.25
intRemainder2 = intRemainder1 Mod 0.25

intDimes = intRemainder2 / 10
.........

even the dollars dont work :( can some one please help.

2007-03-04 17:01:06 · 1 answers · asked by asmi.rani 3 in Computers & Internet Programming & Design

1 answers

MOD is an integer based math function which returns the remainder. (The \ is used to do Integer division Notice it uses the other slash) Since the decimal portion of your numbers are fraction of a dollar, convert these decimal into cents by multiplying by 100

Determine your dollars using an Int function. (NOT the CINT function as it will round)

You may also use x = Math.Truncate(2.78) in VB express

Once you know the dollar ammount subtract it from the original amount 2.78 - 2 = .78
Then multiply by 100 to get cents .78 * 100 = 78

you can now do the MOD and integer division math on the remaing cents starting with the highest

numofQtrs = 78\ 25 (= 3 quarters)
remainder = 78 mod 25 (also = 3 cents)

work your way down the remainder performing integer division and MOD with decending coin values until you get cents as a remainder that is less than a nickle

2007-03-08 15:55:58 · answer #1 · answered by MarkG 7 · 0 0

fedest.com, questions and answers