-
September 8th, 2011, 10:27 PM
#1
[HELP] Converting Seconds 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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|