In order to study further aspects of if statements in C, let's make our
sliding block problem a little more complicated. In the previous sections, we
in effect assumed that our ramp was infinite. Where did we make that
assumption?
Click here for the answer
Let's change our problem by taking into account the length of the ramp and
requiring that the block stop once it reaches the bottom. You can see a
version of our block program that solves this problem by reading
``examples/block2.c'' into Emacs. You can also
view it directly.
The if statement contained in ``block2.c'' is slightly more complicated
than was the case in ``block1.c''. Can you identify two new things that we are
doing?
Click here for the answer
Notice once again how the indentation of ``block2.c'' makes the structure of
the program clear.
Joseph L. Zachary
Hamlet Project
Department of Computer Science
University of Utah