/*** Elapsed Time **********************
Eli attends school from 8:35 until 15:10 each day. He wants to know how many
minutes this is. While he's at it, he decides to write a program that calculates
the difference between any two times. To prevent mistakes, the program must
check whether the times are sensible, e.g. not like 12:85 .
*******************************************/
The most common cause of errors in computer systems is when users type
incorrect data. This program tries to handle
bad data by
rejecting hours greater than 23
and minutes greater than
59. Error handling is generally performed by using if...
commands to perform
a range-check, to see that values
are in the expected range.
This program should also check that the time ha:ma
is actually earlier than hb:mb.
We might be inclined to write the following:
if(
ha > hb || ma > mb)
{ output("The first time should be earlier than the
second"); }
But this isn't really correct. For example, the following times are
valid:
10:30 is earlier than 11:15, even
though 30 > 15.
8:15 is earlier than 8:45, even though 8 is not smaller
than 8.
The correct validity check is more complicated that shown above.