# Thread: Functions! Need help ASAP plz!

1. ## Functions! Need help ASAP plz!

Ok there are seven fuctions. This program calculates the different between two time intervals. The fuction "getTime" has to be called twice by main, once to get the start time, and then again to get the end time. But how can i use that function to do both??? Also, the program runs, but it doesn't calculate anything. Any help is appreciated.

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;

}

// ---------------------------------------------------------------------------------------------

float toHour (int totalsec)

{
int c = 3600;
float totalhour;

totalhour = (float) totalsec / c;

}

// --------------------------------------------------------------------------------------------

float toMin (int totalsec)

{
int c = 60;
float totalmin;

totalmin = (float) totalsec / c;

}

//----------------------------------------------------------------------------------------------

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;
}```

2. nevermind. I figured it out. thx anywayz

3. Just as a matter of interest, why are you using floats to store/display the number of seconds (which you input as integers) and what happens if the start time is greater than the end time? (e.g. if start time is just before midnight and end time is just after)