Pascal. Error in a simple task: the operator was expected to be written, and he met else.

program MaxIn_3; var x, y, z, res: real; begin writeln('Введите целые числа: X, Y, Z'); readln(x, y, z); res := x + y + z; if (res < 1) then begin if (x > y) and (x <> y) then begin y := (y + z) / 2; writeln('X=', x, ',', 'Y=', y, ',', 'Z=', z, '.'); end else begin if (y > x) and (x <> y) then begin x := (y + z) / 2; writeln('X=', x, ',', 'Y=', y, ',', 'Z=', z, '.'); end else begin Writeln('X=Y,',x,'=',y); end; **end;// - если убрать здесь ; то пишет MaxIn_3.pas(29) : Встречено 'else', а ожидалось ';'** **else** //вот здеся ошибка, видимо мне мозгов не хватает понять begin if (x>y) and (x <> y) then begin x:=x*y; writeln('X=', x, ',', 'Y=', y, ',', 'Z=', z, '.'); end else begin if (y>x) and (x <> y) then begin y:=x*y; writeln('X=', x, ',', 'Y=', y, ',', 'Z=', z, '.'); end else begin Writeln('X=Y,',x,'=',y); end; end; end; end; end. 

The PascalABC.NET programming environment, according to my flowchart, everything is correct, sections of operators seem to be all in place, what could be the error? Or do I just squint?

  • The task itself (so that you understand the meaning of this "creation") If the sum of the different three numbers X, Y, Z is less than one, then the smaller of X, Y is replaced by half sum Y and Z, otherwise the larger of X, Y is replaced by the product X * Y. - Aiswe
  • without going into what your code does: you need to remove the semicolon between end and else . - Nofate
  • In Pascal, the else cannot be a semicolon. - Nofate
  • I thought so too ... and when I removed it, I wrote - MaxIn_3.pas (29): I met 'else', and it was expected ';' - Aiswe

1 answer 1

Before THIS else, another 1 end should be ...

 program MaxIn_3; var x, y, z, res: real; begin writeln('Введите целые числа: X, Y, Z'); readln(x, y, z); res := x + y + z; if (res < 1) then begin if (x > y) and (x <> y) then begin y := (y + z) / 2; writeln('X=', x, ',', 'Y=', y, ',', 'Z=', z, '.'); end else begin if (y > x) and (x <> y) then begin x := (y + z) / 2; writeln('X=', x, ',', 'Y=', y, ',', 'Z=', z, '.'); end else begin Writeln('X=Y,',x,'=',y); end end end else begin if (x>y) and (x <> y) then begin x:=x*y; writeln('X=', x, ',', 'Y=', y, ',', 'Z=', z, '.'); end else begin if (y>x) and (x <> y) then begin y:=x*y; writeln('X=', x, ',', 'Y=', y, ',', 'Z=', z, '.'); end else begin Writeln('X=Y,',x,'=',y); end end end end. 

http://pascalabc.net/WDE/?file=04013.pas

  • A good example when code formatting is a must! ) - Kromster