I've written a program in qbasic and it all works apart from one part...I have given a variable the value -100, and at the end of the loop that follows I am adding .01 to the variable, I want the loop to stop when the variable's value reaches 100.01, simple enough but as the program runs the variable value is in the format (x)xx.xxxxx, instead of the (x)xx.xx that I would have hoped for so the loop fails to stop!
Why won't it simlpy add the .01 and keep to 2dp??
The code:
cubicx = -100
DO UNTIL cubicx = 100.01 OR cubicroot3 <> 0 OR INKEY$ = CHR$(27)
IF (cubica * cubicx ^ 3) + (cubicb * cubicx ^ 2) + (cubicc * cubicx) + cubicd = 0 THEN
IF cubicroot1 = 0 THEN
cubicroot1 = cubicx
ELSE
IF cubicroot2 = 0 THEN
cubicroot2 = cubicx
ELSE
cubicroot3 = cubicx
END IF
END IF
END IF
cubicx = cubicx + .01
COLOR 1
LOCATE 16, 3: PRINT "Testing: "; cubicx; " "
COLOR 9
LOOP
What I think it may be doing is adding 0.09999, instead of 0.1, can I make this 0.1 absolute and totally accurate?
Why won't it simlpy add the .01 and keep to 2dp??
The code:
cubicx = -100
DO UNTIL cubicx = 100.01 OR cubicroot3 <> 0 OR INKEY$ = CHR$(27)
IF (cubica * cubicx ^ 3) + (cubicb * cubicx ^ 2) + (cubicc * cubicx) + cubicd = 0 THEN
IF cubicroot1 = 0 THEN
cubicroot1 = cubicx
ELSE
IF cubicroot2 = 0 THEN
cubicroot2 = cubicx
ELSE
cubicroot3 = cubicx
END IF
END IF
END IF
cubicx = cubicx + .01
COLOR 1
LOCATE 16, 3: PRINT "Testing: "; cubicx; " "
COLOR 9
LOOP
What I think it may be doing is adding 0.09999, instead of 0.1, can I make this 0.1 absolute and totally accurate?