Question

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?

Was it helpful?

Solution

$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

OTHER TIPS

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top