Turbo Pascal Homework Problem: Why did Error 57 pop up in a row it shouldn't have?

135 Views Asked by At

I attend 1st grade of Highschool. Recently I had an assignment to do in Turbo Pascal and this happened:

var
   a,b,x,y,n:integer;
begin
   readln(a,b,x,y);
   if a<b and x<y then n:=a+y;
   if a<b and x>y then n:=a+y;
   if a>b and x<y then n:=b+x;
   if a>b and x>y then n:=b+x;
   writeln(n);
end.

An Error 57 appeared in the second if row between "y" and "<".

Can someone explain why this happened?

1

There are 1 best solutions below

0
Blurry Sterk On

A web source indicates that Error 57 is "Then" Expected and because you did not surround your If comparisons with parenthesis brackets the compiler expects that the next word should be a then. Even if the error is not what the source said you still need to enclose your If comparisons with parenthesis brackets if you have more than one comparison in one if

if (a<b) and (x<y) then n:=a+y;

Otherwise the compiler thinks you want the comparison to be

a < b and x

Which will check if a is smaller than the result of b "ANDed" with x