1

我不明白这里发生了什么。你能帮我个忙吗?这是有问题的代码:

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;

编译器在此代码的第 10 行标记错误(否则开始)。错误是:致命:语法错误,; 预期但 ELSE 发现。

如果有人想托盘编译这里是整个代码: http: //pastebin.com/dRg1Lguu

4

2 回答 2

6

请注意,在 Pascal 中,分号是分隔符,而不是终止符。有时这无关紧要,但在某些情况下确实如此,尤其是在else. 您的代码应该是:

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.

于 2012-09-26T14:51:56.737 回答
0

+= 运算符中的问题

于 2012-09-26T14:45:44.887 回答