Can anyone tell me a good algorithm on how to convert seconds into hours, minutes and remaining secs ?
I have this source code, but when you enter a bigger value it gets slowed..
Code:
#include <iostream>
using namespace std;
int main(void)
{
int secondsInput, seconds, hours = 0, minutes = 0;
cout << "enter number of seconds: ";
cin >> secondsInput;
seconds = secondsInput;
int hrs = 3600;
int mins = 60;
for ( int x = 1; x <= secondsInput; x++ ) {
if ( x == hrs) {
hours += 1;
seconds -= 3600;
hrs += 3600;
}
}
for ( int y = 1; y <= seconds; y++ ) {
if ( y == mins ) {
minutes += 1;
mins += 60;
}
}
int z = secondsInput - (( 3600 * hours ) + ( 60 * minutes )); // z = number of seconds
cout << "\n" << secondsInput << " equals to " << hours << " hours " << minutes << " minutes " << z << " seconds";
return 0;
}
Thanks