Re: [HELP] Converting Seconds to Minutes and Hours
Originally Posted by Kifoo
So I'm supposed to make a program which converts seconds into the equivalent hours, minutes, and seconds (if that makes sense)
For example, if I put in 65 seconds, the result would be 1 minute and 5 seconds.
I made this codes but I can't seem to make the hours work. Help please?
Before you write one line of code, have you worked out using simple math and logic how to solve the problem?
What if I give you 6,000 seconds. How does this:
Code:
minute = input / 60;
give you the number of minutes? According to that line of code, the number of minutes will be 100. Is that correct?
What I think you're trying to do is to use the if() statements to bail you out of wrong calculations. As GCDEF stated, those if() statements are totally unnecessary -- make the proper calculations first, and then you don't need those if statements.
Again, work out on paper what the right formula/algorithm is for the number of seconds, minutes and hours. A hint: You work out the hours first, then from the result of that calculation you work out the minutes, and then the result from that, you work out the number of seconds.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; September 9th, 2011 at 09:06 AM.
Bookmarks