What's wrong with this Pascal syntax?

2019-02-28 05:45发布

I can't understand what's going on here. Can you give me a hand? This is the problematic code:

While not EOF(Archi) do begin
  index:= index + 1;
  Read(Archi, Alumno[index]);
  Promes[index] := (Alumno[index].nota1 + Alumno[index].nota2) / 2;
  if Promes[index] >= 6 then begin
     alguPromo := true;
     PromosIndex := PromosIndex + 1;
     Promos[PromosIndex]:= Alumno[index];
  end;
  else begin
       if Promes[index] > 4 then cantiRecu:= cantiRecu + 1;
       else begin
            LibresIndex += 1;
            Libres[LibresIndex] := Alumno[index];
            end;
  end;
end;

The compiler marks error in the line 10 of this code (else begin). The error is: Fatal: Syntax error, ; expected but ELSE found.

If someone wants to tray compile here is the entire code: http://pastebin.com/dRg1Lguu

标签: pascal
2条回答
做自己的国王
2楼-- · 2019-02-28 06:41

Note that in Pascal the semicolon is a separator, not a terminator. Sometimes this doesn't matter, but in some cases it does, particularly before an else. Your code should be:

while not EOF(Archi) do
  begin
    index:= index + 1;
    Read(Archi, Alumno[index]);
    Promes[index] := (Alumno[index].nota1 + Alumno[index].nota2) / 2;
    if Promes[index] >= 6 then
      begin
        alguPromo := true;
        PromosIndex := PromosIndex + 1;
        Promos[PromosIndex] := Alumno[index]
      end
    else
      begin
        if Promes[index] > 4 then
          cantiRecu:= cantiRecu + 1
        else
          begin
            LibresIndex := LibresIndex + 1;
            Libres[LibresIndex] := Alumno[index]
          end
      end
  end

Note that I have re-formatted the code into a more conventional style which helps to make the program logic more easily understood and which also makes it more obvious where the semicolons are needed and where they are not.

查看更多
劳资没心,怎么记你
3楼-- · 2019-02-28 06:42

Looks like problem in += operator

查看更多
登录 后发表回答