This code is not allowed with floating points, it doesn't matter if it's 8 bytes or 4, there are always accuracy errors:
Code:
if car_pos = point_a then
You can do it for example like this:
Code:
if abs(car_pos - point_a)<0.001 then
But this is also extremely rarely used way...
Normally you should organize code so that you can check:
Code:
if car_pos >= point_a then
edit: I'll show what i mean by your code:
Code:
while True do begin
car_pos := car_pos + car_speed;
writeln('car position :',car_pos:2:2);
if car_pos >= point_b then begin
writeln('we are in point b');
break;
end else if car_pos >= point_a then
writeln('we are beyond point a, but before point_b');
end;
Bookmarks