Every program so far did the same thing every time, whatever it was given. From this lesson on, a program can look at its input and decide — print one thing for a positive number and another for a negative one, give a B for 80 and an A for 95. That one ability is behind almost every problem you will solve.
A new start to every program
From this week on, every program begins with two extra lines:
They make cin and cout much faster — the difference between finishing in
time and running out of time once a problem gives you a hundred thousand numbers
to read. They don't change what your program reads or prints, so the only thing
to remember is to put them first, every time.
Comparing two values
A comparison asks a yes-or-no question about two values, and the answer is a
bool: true or false.
| Comparison | True when | With a at 7, b at 5 |
|---|---|---|
a == b | equal | false |
a != b | not equal | true |
a < b | less than | false |
a > b | greater than | true |
