0

(Apologies if the tag is incorrect. I can't find a "Multiplication" tag or similar)

I'm going to be adding a set of 5 numbers up and dividing them to get the average for a java game I am making.

However, there seems to be something wrong with it. I would have thought 15 + 15 / 2 would have been 15, however that seems incorrect.

enter image description here

However, 15 * 2 / 2 yields the expected result.

enter image description here

What is the difference here? Will doing counting up the variables and dividing them by the amount of variables work correctly in my game?

3 Answers3

2

Order of Operations: Division comes before addition. So when you input 15+15/2 you get 15+7.5. To get the answer you want input (15+15)/2.

1

You should probably write $(15+15)/2$ with parentheses and this will yield $15$.

Note that $22.5$ is $15+(15/2)$. In fact Google shows you that this is what it is calculating (taking into account the conventional order of operations).

Guest
  • 4,158
1

Well when you write 15+15/2, the interpretation is $15+\dfrac{15}{2}$. You need brackets to solve this ambiguity: $\dfrac{(15+15)}{2}$

voldemort
  • 13,182