# Thread: [HELP] Converting Secoonds to Minutes and Hours

1. ## [HELP] Converting Secoonds to Minutes and Hours

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?

Code:
```#include <iostream>

using namespace std;

int main (){
int input, hour, minute, second;

cout << "Please enter number of seconds: ";
cin >> input;

minute = input / 60;
hour = input / 3600;
second = minute % 60;

if (input <= 59)
cout << input << " seconds is equivalent to 0 hours, 0 minutes, and " << input << " seconds."  << endl;

else if (input >= 60 || input < 3600)
cout << input << " seconds is equivalent to 0 hours, " << minute << " minutes and " << second << " seconds" << endl;

else if (input >= 3600)
cout << input << " seconds is equivalent to " << hour << " hours, " << minute << " minutes and " << second << " seconds" << endl;

return 0;
}```
All help would be greatly appreciated.

2. Let's look at what your code does for input of 3601

minute, hour, and second will have the values 60, 1, and 0 respectively, but from your description they should have the value 0, 1, and 1 respectively. So the only value you have computed correctly is number of hours.

Try computing number of hours first. Then subtract that number of hours from the input, to get the number of remaining seconds. From that, compute the number of minutes and subtract that number of minutes from input, to get the remaining seconds.

Yes, I've deliberately described in words one option to do what you need to do in code. You could also work back the other way (compute number of seconds using the modulo operator, then minutes, then hours).

Incidentally, you should not need separate output statements for different values of input.

3. Thank you! I got it to work. I kept thinking that I needed to use else if when all I needed was % and /.

Code:
```#include <iostream>

using namespace std;

int main (){
int input, input2, input3, minute, second, hour;

cout << "Please enter number of seconds: ";
cin >> input;

hour = input / 3600;
input2 = input % 3600;
minute = input2 / 60;
input3 = input2 % 60;
second = input3;

cout << input << " seconds is equivalent to " << hour << " hour(s), " << minute << " minute(s), and " << second << " second(s)." << endl;

return 0;
}```