I have running totals of int minutes and int seconds and I can display them as mmm:sss, but I need to convert them into hh:mm:ss. Any ideas? Thanks in advance for your help.

Recommended Answers

All 3 Replies

Here is a code for your query

#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int time,hour,mins,secs;
printf("enter time in secs");
scanf("%d",&time);
g1:
if(time!=0)
{
hour=time/3600;
time=time%3600;
mins=time/60;
time=time%60;
secs=time;
printf("hours=%d\nmins=%d\nsecs=%d",hour,mins,secs);
}
else
{
printf("enter minutes and secs");
scanf("%d%d",&mins,&secs);
time=(mins*60)+secs;
goto g1;
}
getch();
}

The above code will convert "seconds" entered into "hh:mm:ss" form and also if you enter time in "minutes and seconds" this code will convert it into "hh:mm:ss"
Try to implement it in your code
Hope this helped :)

Mark this thread as solved if your problem is solved "Keep coding".

I won't hand the whole answer to you, as that wouldn't be helping you in the long term.
As a starting point, how many minutes are there in every hour? You'll need to divide the number of minutes by that number (ensuring it's stored or cast as an integer so as to truncate any decimals) to get the number of hours. This'll be your HH
You could then use the modulo operator to find out how many minutes are left over at the end. That will become your MM

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.