Syntax error in "Else if"

Asked

Viewed 143 times

-5

With this function my program works, but when I add another error condition:

if ((nota >= 6) && (frequencia >= 75)){
   alert("Aprovado");
}
else if (frequencia >= 50){
   alert("Recuperação");
}
else{
   alert("Reprovado");
}

I want to add one more condition there that error:

    if ((nota >= 6) && (frequencia >= 75)) {
        alert("Aprovado");
    }
    else if (frequencia >= 50) {
        alert("Recuperação");
    }
    else {
        alert("Reprovado");
    }

    //essa
    else if (nota >= 4) {
        alert("Aluno de Recuperação");

    } else {
        alert("Aluno Reprovado");
    }
}
  • 1

    I suggest you read this: [Ask]

  • The else must be the last resort when all else if failed, so he must get last and can only have one.

  • This u tlimo block of comparison that you aim to give error, has to do with the first or are separate things?

  • 1

    To put it simply: The else { is the last. You can’t have another else if after a else {.

1 answer

2


The else if can’t go after the else {. The else must be the last condition, it says something like, all the others are false, so you must execute it. The correct would be to understand the logic first.

I assume note and frequency are important, but only one alert may be shown at a time, there is a lot of strange things in its conditions, but I believe that if frequency below 50 and note below 4 fail, then both can divide the same else

If the student needs to have a frequency of 50 or a grade of 4 (both are not necessary at the same time), then the correct one should be:

if (nota >= 6 && frequencia >= 75) {
    alert("Aprovado");
}
else if (frequencia >= 50) {
    alert("Recuperação");
}
else if (nota >= 4) {
    alert("Aluno de Recuperação");
} else {
    alert("Aluno Reprovado");
}

But if both are necessary, at least the student has a frequency equal to or greater than 50 and a grade equal to or greater than 4, at the same time, to be recovering:

if (nota >= 6 && frequencia >= 75) {
    alert("Aprovado");
}
else if (frequencia >= 50 && nota >= 4) {
    alert("Aluno de Recuperação");
} else {
    alert("Aluno Reprovado");
}
  • 1

    The curious thing is that if the frequency is greater than or equal to 50 and the grade is 10, the student is recovering... kind of weird that rs account.. or better, if the frequency is 100 and the grade is 10, tb is in the background..

  • @dvd the author did not specify the necessary logic, and assuming that the school system of municipal, state and private schools has different methods is not for me to question, we can assume that student is grade 10, but frequency reflects in his qualification (something common to determine in American universities, the presence is an assessment factor as well).

  • Yes, his logic is strange.

  • 1

    @Guilhermenascimento Yes, it was practically the same as you answered. I deleted that answer.

  • @Victorstafusa thanks for editing the/

  • Dude, I got this condigo in pascal learning now put in Avascript can take a look at it in Pascall,,

  • Procedure Resultfin( NOTE, FREQUENCY : real); Begin readln(NOTE, FREQUENCY); if (NOTE >= 60) then Begin if (FREQUENCY >= 75) then Begin writeln('OK'); readln; end Else (then frequency > =50) Begin writeln('RECOVERY'); readln; end Else Begin writeln('REPROVED'); readln; end; end Else if (NOTE >=40) then Begin writeln('RECOVERY'); readln; end Else Begin teln('REPROVED'); readln; end;.

  • @Luccasandrade If it is Objectpascal yes, create a new question for this please.

  • I learned how to use this forum here

  • @Luccasandrade we are not a forum of debate, we are a site of questions and direct answers, that is to say, without any hindrance and assistance, click here to ask a question https://answall.com/questions/ask on the specific subject of Pascal

  • will create now @Guilhermenascimento

Show 6 more comments

Browser other questions tagged

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