Write a method that receives elapsed time for an event in seconds as a parameter. The method then displays the elapsed time in hours, minutes, and seconds. For example, if the elapsed time is 9630 seconds, then the method will display is 2:40:30. Write a main() method that will prompt a user for elapsed time for an event in seconds, and use received value to demonstrate that the method works correctly
#include <iostream>
using namespace std;
int main()
{
int Elapsed_time, hr, min, sec;
const int secPerMin = 60;
const int secPerHr = 60 * secPerMin;
cout << "Please enter the number of seconds elapsed: ";
cin >> Elapsed_time;
hr = Elapsed_time / secPerHr;
Elapsed_time = Elapsed_time % secPerHr;
min = Elapsed_time / secPerMin;
sec = Elapsed_time % secPerMin;
cout << hr << ":" << min << ":" << sec << endl;
return 0;
}
Comments
Leave a comment