2012-09-26 56 views
1

我无法理解这里发生了什么。你能帮我一下吗?这是有问题的代码:这个Pascal语法有什么问题?

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

+0

你确定pascal支持+ =运算符吗? – CAMOBAP

+0

代码有什么问题? – BugFinder

+2

在'else'之前的'end'后面应该有**不是**分号。行'cantiRecu:= cantiRecu + 1'同样不应该有分号。 –

回答

6

注意,在帕斯卡尔分号是分离,不是终止。有时候这并不重要,但在某些情况下它确实如此,特别是在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 

请注意,我已经重新格式化了的代码放到一个更传统的风格,这有助于使程序逻辑更容易理解,并且也使得它更加明显,其中需要分号,并在那里他们不是。

+1

我现在看到它。谢啦。 – sanfilippopablo

0

貌似问题+ =运算符

+0

我加了编译器的错误信息。看一看。 – sanfilippopablo

+1

Free Pascal允许带有特殊参数的C样式增量。这是为了转换的目的,而不是用Pascal直接编写的新代码。 –