- Unary operators
- Unary operators operate on a single item (constant, variable, ...)
- We will look at two (-,+)
- - will flip the value of a number
int x = 7; x = -x; cout << "x is " << x << endl; x = -x; cout << "x is " << x << endl; Will produce x is -7 x is 7

- + will really do nothing.
int x = -7; x = +x; cout << "x is " << x << endl; Will produce x is -7

- Binary operators
- Binary operators work on two operands.
- We will look at 5.
- +
- Adds the two operands and resturs the sum

- -
- subtracts the operand on the right from the operand on the left and returns the difference.

- *
- Multiply the the two operand and return the product

- /
- Divide the left hand operand by the right hand operand.
- / returns the something of the same type as the operands.
- So 5/2 will return an integer (2)
- and 5.0/2.0 will return a float (2.5)
- This sometimes causes strange results.

- % (the modulo operator)
- This is only valid for integers.
- It is the remainder (from fourth grade math division problems)
- 5 % 3 = 2
- 4 % 3 = 1
- 3 % 3 = 0
- 2 % 3 = 2
- modulo is useful for converting units.
If I have 207 pennies, how many pennies would I have left if I traded as many as I could in for dimes. 207 % 10 = 7 207 / 10 = 20 I wouild have 20 dimes and 7 pennies.

- Increment and Decrement
- We perform i = i + 1 often.
- i++ is a shortcut, it is the same as i = i + 1;
- ++i is also the same.
- There can be problems when it is used as part of another statement.
- i++ is a post increment, the value of i is used then it is incremented.
i = 3; cout << i++;

- Will produce a 3 but
i = 3; cout << ++i;

- Will produce a 4. I will have the value of 4 in any case.
- i-- and --i are also available.

- A shortcut
- We also do a = a + b; often
- a += b; is equivelent.
- This is true for most other operators as well.
- a -= b; is the same as a = a - b;

- Write code to convert from Temprature in Celsius to Fahrenheight. F = C*9/5+32, C = 5/9(F-32)
- Complex Arithemetic Expressions
- Order of operations
- Uniary +/-
- Multiply and Divide and Mod left to right
- Add and subtract left to right

- Or more fully in appendix A, page 1012
- Order can be changed with parenthesis ()
- Baily's rule of (), Use Em!
- This is really just like you know how to do with math.

- Order of operations
- Rewrite the code from above.