Syntax error: then but then

Asked

Viewed 60 times

0

I do not know what is happening, each line presents a different error.

Foul then or passes then, in other cases lacking ;

  program Untitled;
    var
    peso:real;
    altura:real;
    idade:integer;
    begin
    writeln('digite seu peso');
      read(peso);
    writeln('digite sua altura');
       read(altura);
    writeln('digite sua idade');
        read(idade);
    if(peso / altura * altura <= 16)then

       writeln('voce esta com magreza extrema')
       else if(peso / altura * altura) >=16) and (peso / altura * altura) <=17)

        writeln('voce esta com magreza moderada')

        else if(peso / altura* altura) in (17..18.5)
             writeln('voce esta com magreza leve')
        else if(peso / altura * altura  >= 18,5) and (peso / altura * altura <= 25)
             writeln('voce esta saudavel')
        else if(peso / altura * altura >=25) and (peso / altura * altura <=30)
            writeln('voce esta com sobre peso')
        else if(peso / altura * altura >=30) and (peso / altura * altura <=35)
            writeln('voce esta com grau de obesidade I procure ajuda')
        else if(peso / altura * altura >=35) and ((peso / altura * altura <=40)
            writeln('voce esta com grau de obesidade II procure ajuda')
        else if(peso / altura * altura >=40) and (peso / altura * altura <=45)
            wirteln('voce esta com grau de obsidade III procure ajuda')


    end

Error log:

'THEN' expected but ')' found

')' expected but '..' found

';' expected but end of file found

How to fix these Syntax errors?

  • Clarify your doubt, don’t just put code in here and wait for people to fix things for you

  • @Tiagorodrigues, in Delphi that’s right, we have little to explain! The question is crystal clear to me! Running his code the question title is obvious!

  • "Executing his code" so I always put here the code with the problem :P I just wanted to say that I had no effort in trying to understand the origin of the problem :) Regards

1 answer

1


Your whole problem starts with indentation, the IDE XE10.2.2 failed to readjust your code. So I did it in hand. However, it is worth remembering that tests in Delphi should be finished with the then, regardless of the amount of tests.

There are still problems in the Codes in separating the tests that are in conjunction with the and.

Mathematical calculations should be separated by () to avoid unexpected results.

Ex:

if a * b = c then

Equals:

if ((a * b) = c) then

They are equal for the same purpose, but the second example is more organized and ready for a unified second:

if ((a * b) = c) and
   ((a * b) > 0) then

Array in Delphi is treated with [ and not with (:

Change in (17..18.5) for in [17..18.5] "here there is still a problem, in the array you cannot use Extended, only Integer, so we will have to extend the test with a and the most"

In Delphi "monetary" values are treated with . and not with ,:

Change 18,5 for 18.5

Rearranging your code would look like this:

  Writeln('digite seu peso');
  Read(peso);
  writeln('digite sua altura');
  read(altura);
  Writeln('digite sua idade');
  Read(idade);
  if (((peso / altura) * altura) <= 16) then
    Writeln('voce esta com magreza extrema')
  else if (((peso / altura) * altura) >= 16) and
          (((peso / altura) * altura) <= 17) then
    Writeln('voce esta com magreza moderada')
  else if (((peso / altura) * altura) >= 17) or
          (((peso / altura) * altura) <= 18.4) then
       Writeln('voce esta com magreza leve')
  else if (((peso / altura) * altura) >= 18.5) and
          (((peso / altura) * altura) <= 25) then
    Writeln('voce esta saudavel')
  else if (((peso / altura) * altura) >= 25) and
          (((peso / altura) * altura) <=30) then
    Writeln('voce esta com sobre peso')
  else if (((peso / altura) * altura) >= 30) and
          (((peso / altura) * altura) <= 35) then
    Writeln('voce esta com grau de obesidade I procure ajuda')
  else if (((peso / altura) * altura) >= 35) and
          (((peso / altura) * altura) <= 40) then
    Writeln('voce esta com grau de obesidade II procure ajuda')
  else if (((peso / altura) * altura) >= 40) and
          (((peso / altura) * altura) <= 45) then
    Writeln('voce esta com grau de obesidade III procure ajuda');

It is worth remembering that a function that returns the result of ((peso / altura) * altura) for a variable would be ideal!

  • Thank you so much junior I’m starting at Delhi thanks for the help

  • If the answer solves your problem, mark it as correct, this way guides the next search to a faster solution!

  • in case of this code there is a need to close it with another end for if or n has problem?

  • no, the end would be necessary if there were a begin after the last then.

  • what command can I use to wait a few seconds before the screen if it closes if this tip is possible

  • Sleep (time_em_mileseconds)

  • detail: (weight / height) * height is always equal to weight. probably the intention was weight / (height * height)

  • other detail: the age variable is not used

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.