UMBC CMSC201, Computer Science I, Fall 1994
Sections 0101, 0102 and Honors
Tuesday September 27, 1994
Assigned Reading: 3.4 - 3.6
Handouts (available on-line): none
Topics Covered:
- Cleared up some confusion about Project 1.
Comments
on Project 1 are posted on WWW.
- Anonymous mail and practice quizzes on WWW should
be working again.
- More loop examples: A program
that adds the digits of a number that the user types in and
sample run.
- A more robust version of the same program that checks
the user's input is positive.
Program and
sample run.
- "99 Bottles of Beer on the Wall".
A program that demonstrates that you should not test
floating point numbers for equality. The culprit
is that 1/5 is not a terminating fractional number in base 2
(similar to 1/3 in base 10).
Program and
sample run.
- A note on how to represent
fractions in base 2.
- A discussion on how to get formatted output using printf.
(E.g., how to left justify, or print out only a certain number of
digits after the decimal point.) Examples for
floating point numbers,
strings, and
integers (last one was not shown in class).
- Some simple programs using an if statement.
Testing an input integer to check if it is even or odd:
Program and sample run.
Testing an input integer to check if it is positive, negative
or zero: Program and sample run.
- Programs which show the "dangling else". Where there are
two if's and only one else, the else
is matched with the closest if.
First program and sample run.
Second program and sample run.
- A very common bug is using one = instead of ==
to test for equality in an if statement. A seemingly
correct program can produce strange results.
Program and sample run.
- Using Boolean variables and operators.
Program and
sample run.
Last Modified:
Fri Sep 30 11:31:52 EDT 1994
Richard Chang, chang@gl.umbc.edu