1
votes

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

2
Are you sure that pascal support += operator? - CAMOBAP
What is the problem with the code? - BugFinder
There should not be a semicolon after the end before the else. Ditto for the line cantiRecu:= cantiRecu + 1 - this should not have a semicolon either. - Paul R
Thanks man! Was the semicolon! I had a suspect that was that, but i couldn't fix it. Done. Thanks man. - sanfilippopablo
@user1491651: OK - I've fleshed this out into a complete answer now - please up-vote and accept it if it has been useful to you. - Paul R

2 Answers

6
votes

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.

0
votes

Looks like problem in += operator