Expression Evaluation

Example:
John wanted Mary to measure the productivity of her department by averaging the income of all the sections weighted by the number of employees in each section. He gave her this formula to use:

A = #workers in section Alpha
a = income for section Alpha
B = #workers in section Beta
b = income for section Beta
C = #workers in section Gamma
c = income for section Gamma

Productivity = (A * a + B * b + C * c) / 3

When Mary used this formula, her figures were incorrect. Do you know why?

Mary computed the productivity this way:

P = 1 * 6000 + 5 * 1000 + 20 * 2000 / 3
P = 6000 + 5 * 1000 + 20 * 2000 / 3
P = 6005 * 1000 + 20 * 2000 / 3
P = 6005000 + 20 * 2000 / 3
P = 6005020 * 2000 / 3
P = 12010040000 / 3
P = 4003346666.67

She performed each calculation in the formula from left to right, but her result is much too large. Notice that when she multiplied by 1000 she included all the previous numbers.

John intended for Mary to solve the problem this way:

P = (1 * 6000 + 5 * 1000 + 20 * 2000) / 3
P = (6000 + 5 * 1000 + 20 * 2000) / 3
P = (6000 + 5000 + 20 * 2000) / 3
P = (6000 + 5000 + 40000) / 3
P = (51000) / 3
P = 17000


Definition:
An expression is a string of values and operators to be evaluated.

The right side of the formula given above is an expression. As the example illustrates, there are rules regarding the order of performing the operations in an expression. Mary was right to approach the problem from left to right but she needed to know about the order of precedence for the operators in an expression.

Follow the order below and you will always evaluate your expressions properly. Begin with the top and work your way down the list.

OPERATOR PRECEDENCE
OperatorsDescription
( )parenthesis--used to group expressions
^exponentiation
* /multiplication and division
+ -addition and subtraction



Now here are some expressions for you to evaluate. When you think you have the right answers, check yourself by clicking on the answer box below.

1. 5 + 4 * 3 - 1/2
2. 5 + (4 * 3) - 1/2
3. 5 + (4 * 3 - 1)/2
4. (5 + 4) * 3 - 1/2
5. 5 + 4 * (3 - 1)/2
6. 5 + 4 * 3^2 - 1/2
7. 5 + (4 * 3)^2 - 1/2
8. 5 + (4 * 3^2 - 1)/2
9. 5 + 4 * (-3) - 1/2
10. John needs to compute his travel expenses for June. He needs to be reimbursed for $2.00 tolls paid each way on his trips to work and for $.25/mile for each 16 mile round trip. John did not work on the four weekends of June and he took one sick day. How much money is due to John?
11. Mary wants to know the average travel cost expenses per person for her three person section. The expense reports for her people are:

EXPENSE REPORTS
EmployeeMonthAmount
JohnJanuary$160
February$144
BethJanuary$96
February$72
ThomasJanuary$28
February$22
Based on these reports what is the monthly average per employee for the section?