Skip to content

Instantly share code, notes, and snippets.

@WA9ACE
Created September 13, 2011 18:16
Show Gist options
  • Save WA9ACE/1214561 to your computer and use it in GitHub Desktop.
Save WA9ACE/1214561 to your computer and use it in GitHub Desktop.
Changes seconds elapsed to hours, minutes, and seconds
#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