DAY13
Monday, 11 June 2012
Today we will talk about:
-
the if statement for making decisions;
-
the if/else and if/elseif/else statements;
-
nested or double if statements;
-
the logical AND, OR, and NOT operators;
-
Boolean variables;
Note: the "switch" statement is not a very important part of C.
It's complicated and tricky and easy to use incorrectly. We will go over it,
but you should concentrate on the if/then/else and boolean information.
Note #2: the "conditional operator" or "question mark operator"
is a horrible piece of C, and I won't talk about it, and it won't appear
on any lab, homework, or exam.
Programs and functions we might talk about:
-
guess_again.c,
guess the program's secret number.
-
min1.c, determines the minimum of A and B using an if.
-
min2.c, determines the minimum of A and B using if/else.
-
min3.c, determines the minimum of A, B, C using two if's.
-
min4.c, determines the minimum of A, B, C using if/elseif/else.
-
month_length.c,
prints the number of days in a month (ignoring leap year).
-
next_date.c, determines the day after M/D/Y.
-
next_date2.c, determines the day after M/D/Y.
Checks for leap year. Also uses boolean variables.
-
p6.5.c, determines if Y is a leap year.
-
p6.8a.c, evaluates simple expressions like 1+2, 3*4, 5/6, 7-8.
Last revised on 11 June 2012.