Home computickets An error in a simple task: an operator was expected to write,...

An error in a simple task: an operator was expected to write, but met else

Author

Date

Category

Pascal. An error in a simple task: an operator was expected to write, but met else.

program MaxIn_3;
var
  x, y, z, res: real;
begin
  writeln ('Enter integers: X, Y, Z');
  readln (x, y, z);
  res: = x + y + z;
  if (res & lt; 1) then
  begin
    if (x & gt; y) and (x & lt; & gt; y) then
    begin
      y: = (y + z) / 2;
      writeln ('X =', x, ',', 'Y =', y, ',', 'Z =', z, '.');
    end
      else
      begin
      if (y & gt; x) and (x & lt; & gt; y) then
         begin
          x: = (y + z) / 2;
          writeln ('X =', x, ',', 'Y =', y, ',', 'Z =', z, '.');
         end
         else
         begin
         Writeln ('X = Y,', x, '=', y);
         end;
      ** end; // - if removed here; then MaxIn_3.pas (29) writes: Met 'else', but expected ';' **
     ** else ** // here is the error, apparently I don't have enough brains to understand
      begin
      if (x & gt; y) and (x & lt; & gt; y) then
       begin
       x: = x * y;
       writeln ('X =', x, ',', 'Y =', y, ',', 'Z =', z, '.');
       end
        else
         begin
         if (y & gt; x) and (x & lt; & gt; 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.

Answer 1, authority 100%

Before THIS else, 1 more end must be …

program MaxIn_3;
var
 x, y, z, res: real;
begin
 writeln ('Enter integers: X, Y, Z');
 readln (x, y, z);
 res: = x + y + z;
 if (res & lt; 1) then
  begin
   if (x & gt; y) and (x & lt; & gt; y) then
    begin
     y: = (y + z) / 2;
     writeln ('X =', x, ',', 'Y =', y, ',', 'Z =', z, '.');
    end
   else
    begin
     if (y & gt; x) and (x & lt; & gt; 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 & gt; y) and (x & lt; & gt; y) then
    begin
     x: = x * y;
     writeln ('X =', x, ',', 'Y =', y, ',', 'Z =', z, '.');
    end
   else
    begin
     if (y & gt; x) and (x & lt; & gt; 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

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions