Code:
#include <stdio.h>
void getTime (int* h, int* m, int* s);
void duration (int h, int m, int s, int endh, int endm, int ends, float* totalhour, float* totalmin);
int calcDuration (int h, int m, int s, int endh, int endm, int ends);
float toHour (int totalsec);
float toMin (int totalsec);
void printDuration (float* totalhour, float* totalmin);
int main(void)
{
int h, m, s, endh, endm, ends;
float totalhour, totalmin;
getTime (&h, &m, &s);
getTime (&endh, &endm, &ends);
duration (h, m, s, endh, endm, ends, &totalhour, &totalmin);
printDuration (&totalhour, &totalmin);
return 0;
}
// --------------------------------------------------------------------------------------------
void getTime (int* h, int* m, int* s)
{
printf ("Enter time (hh:mm:ss): ");
scanf ("%d:%d:%d", h, m, s);
return;
}
// -------------------------------------------------------------------------------------------
void duration (int h, int m, int s, int endh, int endm, int ends,
float* totalhour, float* totalmin)
{
int totalsec;
totalsec = calcDuration (h, m, s, endh, endm, ends);
*totalhour = toHour (totalsec);
*totalmin = toMin (totalsec);
return;
}
// ---------------------------------------------------------------------------------------------
int calcDuration (int h, int m, int s, int endh, int endm, int ends)
{
int startsec, endsec, totalsec;
int c = 3600;
int b = 60;
startsec = (h * c) + (m * b) + s;
endsec = (endh * c) + (endm * b) + ends;
totalsec = endsec - startsec;
return totalsec;
}
// ---------------------------------------------------------------------------------------------
float toHour (int totalsec)
{
int c = 3600;
float totalhour;
totalhour = (float) totalsec / c;
return totalhour;
}
// --------------------------------------------------------------------------------------------
float toMin (int totalsec)
{
int c = 60;
float totalmin;
totalmin = (float) totalsec / c;
return totalmin;
}
//----------------------------------------------------------------------------------------------
void printDuration (float* totalhour, float* totalmin)
{
printf ("The time in hours is: %9.2f\n", &totalhour);
printf ("The time in minutes is: %7.2f\n", &totalmin);
return;
}