Pergunta

I am working on a Facebook App that needs to be able to average three numbers. But, it always return 0 as the answer. Here is my code:

$y = 100;
$n = 250;
$m = 300;
$number = ($y + $n + $m / 3);
echo 'Index: '.$number;

It always displays Index: 0

Any ideas?

Foi útil?

Solução

$y = 100;
$n = 250;
$m = 300;
$number = ($y + $n + $m) / 3;
echo 'Index: '.$number;

Also - you missed ; in the end of the first 3 lines

Outras dicas

Your parentheses are grouped wrongly. You should be doing:

$number = ($y + $n + $m) / 3;

Two problems:

You are missing ; at the end of these lines:

$y = 100
$n = 250
$m = 300

And to / has higher precedence than + so you need to do:

$number = ($y + $n + $m) / 3;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top