V22.0002 - ASSIGNMENT 1
Write a program that computes the difference between two time readings.
The times are read into the program as integers of at most 6 digits (without leading zeros): hhmmss,
where hh stands for hour, mm minutes and ss seconds. The
difference should be displayed in the same format (called "military format").
The difference can be both positive and negative. It doesn't matter in which direction it's negative, as long as it's
consistent. That is, you can subtract the second time from the first time or the second time from the first.
For the purposes of this assignment you can assume that the inputs are correct
(that is, you are not going to have more than 59seconds or more than 59 minutes).
Ex (the blue text indicates user input):
Enter first time: 230000
Enter second time: 210001
Time difference: 15959
Enter first time: 123245
Enter second time: 112955
Time difference: 10250
Enter first time: 23245
Enter second time: 32815
Time difference: -5530
Enter first time: 245
Enter second time: 235
Time difference: 10
Notes and Hints:
- The above example is for 4 separate runs corresponding to the following times.
Note that ere we are subtracting the second time from the first time.
- 11:00:00 PM and 9:00:01 PM [difference is 1:59:59, or 1 hr 59 mins 59 secs]
- 12:32:45 PM and 11:29:55 AM [= 1:02:50, or 1 hr 2 mins and 50 secs]
- 2:32:45 AM and 3:28:15 AM [= -0:55:30, or negative 55 mins 30 secs]
- 0:02:45 AM and 0:02:35 AM [= 0:00:10, or in0other words 10 seconds]
- example algorithm for this assignment:
- Isolate the different parts of each time: hours, minutes and
seconds (use the mod operator % ... hint, hint, hint; you could use integer division instead, which may be
more intuitive for some).
- Compute the time in terms of seconds (1 hour = 3600 seconds, 1
minute = 60 seconds).
- Compute the difference in seconds.
- Convert the above number into hours, minutes and seconds
(again the mod operator %, but with a different base ... hint, hint, hint).
- Create the new 6-digit integer (the time in military format) and print it.
- You are NOT being asked to convert a PM or AM time to military time format. The user should be entering the time in military format.