By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,917 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,917 IT Pros & Developers. It's quick & easy.

Converting Seconds into hours, minutes and seconds

P: 1
I'm trying to write a program that takes a user inputted number of seconds and converts it into hours, minutes and seconds. So for instance, the program prompts the user for seconds, lets say 1000 seconds are inputted. The program will output "there are 0 hours, 16 minutes and 40 seconds in 1000 seconds." I've been trying to do some type of nested loop...but I'm having problems. Any help would be much appreciated! Thanks
Jan 31 '07 #1
Share this Question
Share on Google+
1 Reply


Ganon11
Expert 2.5K+
P: 3,652
There should be no loops required. You should only need division and modulus division to complete this project.

What will you need to do to convert seconds into minutes? Well, 1 Minute = 60 seconds. So x seconds = x/60 minutes. Anything left over (the remainder - use %!) will remain as seconds.

Now that you have minutes, what do you need to do to convert minutes into hours? Well, since 1 hour = 60 minutes, x minutes = x/60 hours, and the remainder will be however many minutes you have.
Jan 31 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.