In the third week you learned:
- Miscellaneous:
- When you prompt users for input, the message should be clear, indicating
what type of input you're expecting from them
- You should not have "hard-coded" numbers in your program - instead
these should be defined as const variables.
- Const variables must be (and other variables may be) initialized
on the line where you declare them. There are two styles of initializing.
For example:
const float pi = 3.14159;
const int days_per_week(7);
The latter method is preferable.
- const variables may be declared as global variables (declared outside of
main
), but don't declare non-const variables as global variables.
- You can put special characters into strings. Examples include
\n (for new line), \t (for tab) or \\ (for backslash).
- Arithmetic:
- Assignment statements can be strung together, for example:
x = y = z+2;
The assignments are evaluated from right to left.
- Compound assignment statements, such as +=, *=, -=, /=
For example, x += y; is a synonym for x = x + y; and x *= (1+interest); is a
synonym for x = x * (1+interest);
- Increment and decrement operators and what they mean (such as x++;
y = ++z; rounds_left--; etc. (there's a difference between post-increment
and pre-increment, between post-decrement and pre-decrement)
- The mod operator % (x%y gives the remainder when x is divided by y)
- Selection structures:
- boolean expressions (evaluate to true/false)
- relational operators (==, <, <=, >, >=)
- logical operators (&&, ||)
- "if" statement (one-way selection), its form, its flowchart, examples
- "if/else" statement (two-way selection), its form, its flowchart,
examples
- nested if/else statements (multi-way selection), the form, the
flowchart, example
- compound statements (list statements within a pair of curly braces,
and they're treated as one statement for the purpose of if/else)
- formatting conventions (indentation) for selection structures