Thursday, October 05, 2006

Error 4: (No compiler message)

Type:
Logic
Screenshot: 1
Description:
An error occured while testing my CashReg program's change calculation process, where, if the change required had decimals above .5, the change recommended would come in negatives. I found this to be an error in the formula I used in order to remove values above a dollar from the change variable.
The formula, which was at the time:
dblChange = dblChange - Math.round(dblChange)
Instead of working with a double, since the rounding method I used had obvious holes, I instead used a variable casting method, changing the double-change into an integer, a process where it would automatically round down.
Editted formula:
dblChange = dblChange - (int)dblChange;
This change in the formula promptly fixed the problem.

No comments: