DJKlacka
04-13-2003, 06:45 PM
I am supposed to write a program that is interactive and converts seconds to hours, minutes, and seconds. For an input of 7903 seconds, the output should be:
7903 sec. = 2 hr. 11 min. 43 sec.
This is what I have and it doesnt seem to be working very well.. if I type in any amount of seconds, it doesnt give me the leftover seconds it gives me a certain amount of hours that is wrong, then a godly isane amount of minutes, and then it gives me the same amount of seconds that the input is.
#include <iostream>
using namespace std;
int main(){
int s, hours, minutes;
while (s >= 3600)
{ s = s - 3600;
hours++; }
while (s >= 60)
{ s = s - 60;
minutes++; }
cin >> s;
cout << hours << "hr." << minutes
<< "min." << s << "sec." << endl;
return 0;
}
Please help me out.............
7903 sec. = 2 hr. 11 min. 43 sec.
This is what I have and it doesnt seem to be working very well.. if I type in any amount of seconds, it doesnt give me the leftover seconds it gives me a certain amount of hours that is wrong, then a godly isane amount of minutes, and then it gives me the same amount of seconds that the input is.
#include <iostream>
using namespace std;
int main(){
int s, hours, minutes;
while (s >= 3600)
{ s = s - 3600;
hours++; }
while (s >= 60)
{ s = s - 60;
minutes++; }
cin >> s;
cout << hours << "hr." << minutes
<< "min." << s << "sec." << endl;
return 0;
}
Please help me out.............