0

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.

3
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by rookieNeedsHelp
0

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".

Edited by <Anurag>: to add details

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.