Topical Information

This program will help you develop a useful application from output, calculations (including modulo), and library functions. It is also a good place to use constants.

Program Information

Write a program that tells the user what time of day it is in 24-hour (military) time (AM-PM is an option below). This program will be unusual in that there will be no user input (excepting options). Simply output the time of day to the user and exit the program. Be sure to report the results neatly.

Hints:


People keep wanting to call the functions localtime and asctime from the standard C library ctime here. Just don't! The goal of this program is for you to code this process yourself! (And asctime leaves a mess behind you would probably forget to clean up even if you knew how!)


As an example, you might have the program interaction look something like:

$ ./time.out

                 Welcome to the Time-of-Day Program!!!

It is currently 12:59:59.

Thank you for using the ToDP!!

Endeavor to have a timely day!

$ ./time.out

                 Welcome to the Time-of-Day Program!!!

It is currently 13:0:9.

Thank you for using the ToDP!!

Endeavor to have a timely day!

$

(Note: Notice that the second time isn't terribly pretty. That's fine. If you want to fix it, see the option below.)

(Note: You'll find that the times are off by several hours. That's because they are the time in Greenwich, England — see the link above. Adjusting for this is an option below.)

Thought Provoking Questions

  1. If you had a large number of inches (say 103054), how would you determine how many feet and inches there were after yards and miles had been accounted for ...but without going through those intermediate calculations to determine miles and yards! (Hint: There are 1 foot and 10 inches left.)
  2. How does this relate to having a huge number of seconds and trying to calculate hours, minutes, and seconds without having to remove decades, years, months, weeks, and days first?

Be sure to look for any helpful resources you can in the notes on programming with ctime's time() function. You can never tell when something might come in handy!

This assignment is (Level 2).


Options


Total Level Possible

If you did all above options, this lab could be worth as much as (Level 10.5).