Created
September 13, 2011 18:16
-
-
Save WA9ACE/1214561 to your computer and use it in GitHub Desktop.
Changes seconds elapsed to hours, minutes, and seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main (int argc, char const *argv[]) | |
{ | |
// Author: Caleb Albritton | |
// Student ID: 810608 | |
int hours; | |
int minutes; | |
int seconds; | |
cout << "Enter the elapsed time in seconds: "; | |
cin >> seconds; | |
cout << "You have entered " << seconds << " seconds" << endl; | |
// We first get minutes by dividing by seconds | |
minutes = seconds/60; | |
hours = minutes/60; | |
// to get the left over minutes we have to modulo the minutes over itself; | |
minutes = minutes%60; | |
// same with seconds | |
seconds = seconds%minutes; | |
std::cout << hours << ":" | |
<< minutes << ":" | |
<< seconds | |
<< endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment