April 30th, 2013, 01:05 AM
Help with displaying time please
I am making a simple program (for learning purposes) that has a main goal of gathering 3 sets of information from user;
-A Starting time
-A Finishing time
-Number of people
The program then works out the time between start and finish (for example; 7 hours) then divides it evenly between the number of people. For example: 5 people to complete 5 hours (keep it simple)
Person 1 will start at 1100 and finish at 1200
person 2 will start at 1200 and finish at 1300
I am having an issue with the display of time, I have researched but being very new I am looking for needle in a hay stack.
So lets say for example the starting time is 1400(24h time) and the program has worked out that each person is required to work 61 minutes (for ease of explanation), I am not sure how to simply have the print function display "1501" appose to "1461"
Is there something I could use that would allow me to apply a integer to a time function ((if its possible)to designate start time) and then be able to add integers on top of that over and over (as required) with the program applying the math to 'time rules'(60 mins in a hour etc)
I hope I explained this well enough, any help would be fantastic.
April 30th, 2013, 01:56 AM
April 30th, 2013, 01:59 AM
The time functions are prototyped in the header file, time.h .
Time, which is of type time_t, is the number of seconds since the beginning of time at midnight starting 1970 Jan 01. time.h also defines struct tm whose fields are time units for date and time and the like. There are functions to convert a time_t to a struct tm and a struct tm to a time_t. And functions that will take one or the other and output a string in whatever format you choose.
Look them up and see what may apply. There should be plenty of examples on-line.