+3

How to convert seconds to minutes, hours, and days?

c++

1/24/2017 11:23:06 PM

Kyle Martin

25 Answers

New Answer

+16

Not for the accurate result. If you want to split the seconds into the above you can use this: int sec = 3700, mins, hours, days; sec -= (60 * 60 * 24) * (hours = sec / (60 * 60 * 24)); sec -= (60 * 60) * (days = sec / (60 * 60)); sec -= 60 * (mins = sec / 60);

+4

It would be 1 hour 1 minute and 40 seconds (cmon, basic math xD), but whatever. You know I gave you the complete code for this 10 comments ago? Well, here it is again: int input, sec, mins, hours, days; cout << "Enter a number:" << endl; cin >> input; sec = input; sec -= (60 * 60 * 24) * (hours = sec / (60 * 60 * 24)); sec -= (60 * 60) * (days = sec / (60 * 60)); sec -= 60 * (mins = sec / 60); cout << input << " seconds are " << days << " day(s) " << hours << " hour(s) " << mins << " minute(s) and " << sec << " second(s)" << endl; And don't say you ONLY want hours if clearly you also want it to display minutes seconds and days at the same time^^

+1

In c++ Int main( ) { Int s,d,h,m,s1; Cout‹‹"enter time in seconds"; Cin››s; d=s/86400; /*here 1 day= 86400 seconds. So it is the formula of finding days from hours*/ S=s%86400 ;/*% stands for modulus or mod*/ H=s/3600; S=s%3600; M=s/60; S2=s%60; Cout‹‹d‹‹"days "‹‹h‹‹"hours "‹‹m‹‹" minutes "‹‹s‹‹" seconds "; Return 0; } This is also known as denomination programme

+1

to convert seconds to minutes ÷ seconds by 60, minutez to hours ÷ minutes by 60, hours to days divide hours by 24! SIMPLE

+1

You still didn't answer what the exact output for 3700 seconds should look like. Apparently you don't want it to be 1 hour (rounded) and you also don't want it to be 1.0278 hours (exact, but decimals), so what do you want? 37/36 hours? 10278e-4 hours?

0

Minutes = Seconds * 60 Hours = Minutes * 60 Hours = Seconds * 60 * 60 Hours = Seconds * 3600 Days = Hours * 24 Days = Seconds * 3600 * 24 Days = Seconds * 86400

0

"65days 1hour 37minutes 67 seconds"? @Kyle 🤣... 67 seconds

0

problem solved thank u

0

So, problem solved now or any questions left?

0

I mean pseudocode....sorry I've been doing hw all day..

0

I've only have done c++

0

my bad I'm still getting used to c++

0

like 65 days 1 hour 37 minutes 67 seconds

0

I know. I'm trying to get it using a math equation

0

You can't just only display the hours and then not round the result or have some decimals, that's not how it works...

0

without decimals. I need an exact answer

0

how many hours for those seconds

0

What output do you want? Let's say you have 3700 seconds, what should the output look like?

0

won't it be truncated though?

0

If you define the seconds, minutes, hours and days as integer you won't have any decimals. int input, sec, mins, hours, days; cout << "Enter a number:" << endl; cin >> input; sec = input; sec -= (60 * 60 * 24) * (hours = sec / (60 * 60 * 24)); sec -= (60 * 60) * (days = sec / (60 * 60)); sec -= 60 * (mins = sec / 60); cout << input << " seconds are " << days << " day(s) " << hours << " hour(s) " << mins << " minute(s) and " << sec << " second(s)" << endl;