Well my current code is:
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
typedef struct
{
int hr;
int min;
int sec;
} TIME;
TIME sTime;
TIME fTime;
TIME tTime;
printf("Calculate total time between start and finish. Format for data is hh:mm:ss\n");
printf("\nEnter a start time: ");
scanf("%d:%d:%d", &sTime.hr, &sTime.min, &sTime.sec);
printf("\nEnter a finish time: ");
scanf("%d:%d:%d", &fTime.hr, &fTime.min, &fTime.sec);
tTime.hr = fTime.hr - sTime.hr;
tTime.min = fTime.min - sTime.min;
tTime.sec = fTime.sec - sTime.sec;
printf("\n\n\nThe total time: %2d hr(s),%2d min(s), and%2d sec(s)\n", tTime);
}
Which works, but I am trying to clear up some data entry problems so that no matter what the user enters it will give the suer the correct information. My first step is to fix the problem with the fact that if they enter 12:01:01 as a strt time and end time of 01:01:01 the get a -11 total time instead of 1.
What I was thinking I would like to do is:
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
typedef struct
{
int hr;
int min;
int sec;
} TIME;
TIME sTime;
TIME fTime;
TIME tTime;
printf("Calculate total time between start and finish. Format for data is hh:mm:ss\n");
printf("\nEnter a start time: ");
scanf("%d:%d:%d", &sTime.hr, &sTime.min, &sTime.sec);
printf("\nEnter a finish time: ");
scanf("%d:%d:%d", &fTime.hr, &fTime.min, &fTime.sec);
tTime.hr = fTime.hr - sTime.hr;
tTime.min = fTime.min - sTime.min;
tTime.sec = fTime.sec - sTime.sec;
if tTime.hr < 0
tTime.hr = tTime.hr + 12
printf("\n\n\nThe total time: %2d hr(s),%2d min(s), and%2d sec(s)\n", tTime);
}
But I get a syntax error : identifier 'tTime'. I am still trying to get a grip on structures, but am confused as to exactly how they work I guess. I figure once I get this down, I can do some similar stuff to ensure minute and seconds are not >60 and that everything is numeric and not an alpha character. Any help is appreciated.
Thanks,
DD