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 <cstddef>
#include <iostream>
/**
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
*/
int main() {
std::cout << "Time in seconds: ";
size_t time;
std::cin >> time;
size_t s = time % 60;
time /= 60;
size_t m = time % 60;
time /= 60;
size_t h = time;
std::cout << h << ":"
<< (m < 10? "0": "") << m << ":"
<< (s < 10? "0": "") << s << '\n';
return 0;
}
Comments
Leave a comment