Need help with my program, please take a look
I am working on a program that is supposed to get the result from a script(based on PL/0).
For example:
if the script below is enterd into my program
Code:
program main;
var id1,id2,id3;
begin
id1=1;
id2=1500;
id3=0;
while id2>100 do
begin
id2=id2-id1;
id3=id3+1;
end;
end
.
then my program would get the result:
id3=1400,id2=100,id1=1
and so far, it is correct.
but when the script changes into this, bad things happened :(
Code:
program main;
var id1,id2,id3;
begin
id1=0.01;
id2=5;
id3=0;
while id2>0 do
begin
id2=id2-id1;
id3=id3+1;
end;
end
.
my program gave me a weird answer:
id3=501,id2=-0.01,id1=0.01
the while statement has run one more time than it should be. :confused:
And that is not all, if i initialize the id2 to 1 in the script above.
Code:
program main;
var id1,id2,id3;
begin
id1=0.01;
id2=1;
id3=0;
while id2>0 do
begin
id2=id2-id1;
id3=id3+1;
end;
end
.
The result turned to "id3=100,id2=-7.5287e-16,id1=0.01".
how could the id2 be "-7.5287e-16"?
Could anyone tell me where the problem is? It really got me confused.
Thanks