ejercicio.pas(10,9) Fatal: Syntax error, ":" expected but "(" found

Viewed 39

I receive an error

ejercicio.pas(10,9) Fatal: Syntax error, ":" expected but "(" found

in the following code

procedure darUnPaso(var x, y: integer; vx, vy: integer);
begin
  x := x + vx;
  y := y + vy; 
end;
    
function estanChocando(x1, y1, x2, y2: integer): boolean;
(* precondition: ( sqr(x2-x1))+sqr(y2-y1)) mayor o igual a 0*)     
var
  true: boolean;
  dist((x1, y1), (x2, y2)): real;
begin
  true:= (dist((x1, y1), (x2, y2))) < RADIO + RADIO;
  (dist((x1, y1);(x2, y2))):= sqrt((sqr(x2-x1))+(sqr(y2-y1)));                                                               
  if true then
    estanChocando:= true
end;
    
function esPosicionValida(x1, y1: integer): boolean;
var true:
    boolean;
begin
  true:=((RADIO<=x1<=ANCHO-RADIO) and
    (RADIO<=y1<=ALTO-RADIO));
  if true then
    esPosicionValida:=true
end;
    
function predecirColision(x1,y1,vx1,vy1,x2,y2,vx2,vy2: integer): integer; 
(*ninguna de las pelotas està detenida y ambas pelotas
    estàn en posiciones vàlidas*)
var true: boolean; 
begin
  true := estanChocando(x1,y1,x2,y2) or ((esPosicionValida(x1,y1) and (esPosicionValida(x2,y2));
    
  if true then
    predecirColision:=darUnPaso
  else
    predecirColision:=-1
end;

I can't find the error in the code in

dist((x1, y1), (x2, y2)): real;
1 Answers

You get the syntax error message because you have declared

dist((x1, y1), (x2, y2)): real;

to be a variable, but it doesn't follow the rules of variable declaration which should be

name: type;

you can not have parenteses, commas nor spaces in a name.

Perhaps you meant to write

dist: real;

and then use it like

dist := sqrt((sqr(x2-x1))+(sqr(y2-y1)));

You have also declared the variable

true: boolean;

which is in conflict with language defined constant True

I suggest you change that to something like:

b: boolean;

which then can be assigned a value like

b := True; // or b := any boolean formula
Related