Each else clause is necessary. If they're left out a grade of
100 would cause all the messages to be printed. In the code
above a grade of 75 will cause the guard (grade > 70)
to be true, and that's the only guard that will be
evaluated as true.
27 < 20 , which evaluates to false,
which is 0. This is because the relational operator < has
lower precedence than the arithmetic operators (see Howto A and
Table A.4 on 715).
The expression
9 * 1 * 5 because (3 < 4)
is true which is 1. This is why 45 is output. The parentheses
are needed because < (less than); has lower precedence than *
(multiplication).
cout << 9 * 5 < 45 <<
endl generates 0 as output because it is false and false
corresponds to 0 for output. If <= were used instead of <
then 1 would be printed since the statement would be true.
The expression (9*5 < 45 < 30) evaluates to
45 < 45 < 30 which evaluates to 0
< 30 which is 1 (true). This depends on the
associativity of the < operator.
To use a function:
101.269 feet 60 minutes 1 mile
------------ * ---------- * ---------
1 minute 1 hour 5,280 feet
x is
negative when
x >= 0 will be
false, and the call to sqrt will NOT be made
because the whole expression must be false. This is one of the
nice things about short-circuit evaluation of boolean
expressions.
return sqrt(a*a + b*b - 2*a*b*cos(angle))
cin >> a >> b >> c
is treated like ((cin >> ) >> b) >> c .
TensPrefix(10 * 22 / 10)
which is TensPrefix(220/10) which is
TensPrefix(22) because * and / have equal
precedence so in the absence of parentheses the order of
evaluation is left-to-right.
It's ok to use % here negative numbers because although the value of (-3 % 2) may not be 1 --- it's -1 on most systems --- this value is NOT zero, so it's use in the code above will work since any negative even number will yield a remainder of zero when divided by 2, even in C++.
If you want to avoid using the % (mod) operator, the code below can be used: