Jump to content

What's wrong?


Meg_Griffin

Recommended Posts

Hi guys,please help me with my code. Everything is fine,except for this line: elseif (3.2<$media<7) echo "Em recuperação"; It generates a syntax error: Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\questao_01.php on line 49 So,the question is: if the specified condition in my exercise is 3.2<media<7 why is this wrong? .

Link to comment
Share on other sites

} elseif  (3.2<$media<7) {echo "Em recuperação";}

Based on your question as written.

Edited by niche
Link to comment
Share on other sites

The problem is that you're trying to make two comparisons in one statement. You need to separate them:

elseif (3.2 < $media && $media < 7)

Curly braces are not a requirement and it is syntactically correct to omit them. The only problem being that only the next line of code will be considered part of the block.

  • Like 1
Link to comment
Share on other sites

not considered part of the block.
As in not part of the if-elseif structure? Edited by niche
Link to comment
Share on other sites

You misquoted my post. When curly braces are omitted only one line of code is considered the part of the block of code that is associated with the keyword. The keyword can be if, else, elseif, else if, for, while, foreach.

Link to comment
Share on other sites

Ingolme,thank you.But there's one more doubt...why does this code show me a different output? It outputs "reprovado" instead of "sem notas cadastradas". elseif ($media=="indefinido") echo "Sem notas cadastradas";

Link to comment
Share on other sites

please post your relevant code

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...