What's wrong with this Pascal syntax?

后端 未结 2 1111
醉梦人生
醉梦人生 2021-01-23 10:01

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,         


        
相关标签:
2条回答
  • 2021-01-23 10:15

    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 讨论(0)
  • 2021-01-23 10:16

    Looks like problem in += operator

    0 讨论(0)
提交回复
热议问题