# Thread: Any assistance would be greatly appreciated

1. Code:
```#include <stdio.h>

#define MINS_HR 60 //define minutes per hour
#define SECS_MIN 60 //define seconds per minute

int main(void)	{

int total;
int h, m, s;

printf("How many seconds whould you like to convert?\n");
scanf("%d", &total);

h = (total / (MINS_HR * SECS_MIN));
if (h >= 1)	{
total = total - (MINS_HR * SECS_MIN);
if (h <= 0)	{
h = 0;
}
}

m = (total / SECS_MIN);
if (m >= 1)	{
total = (total - (SECS_MIN * m));
if (m <= 0)	{
m = 0;
}
}

s = total;
printf("%d:%d:%d", h, m, s);
}```
this program is supposed to convert seconds to hours:minutes:seconds...for example, 4000 seconds would be 01:06:40.

is this the most efficient way? i've noticed that it doesn't work for all inputs. higher amount of seconds, the less accurate the output is. please advise.

2. This is a lot easier if you also use the % modulo operator.
h = total / 3600;
ms = total % 3600;
m = ms / 60;
s = ms % 60;

3. Code:
`		total = total - (MINS_HR * SECS_MIN);`
shouldn't this be:

Code:
`		total = total - (MINS_HR * SECS_MIN * h);`

4. haha, oh man you don't know how much i appreciate you guys

thanks so much,
michael

Popular pages Recent additions