Answer to Question #234786 in C++ for Katso

Question #234786
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. Save the file as ElapsedTime.cpp
3
1
Expert's answer
2021-09-08T15:49:59-0400
#include <iostream>
/*
*We use the fact that the result of division operations for an integer is an integer
*/
void GetTime(int s) {
    std::cerr << s / 3600 << ":" << (s - (s / 3600) * 3600) / 60 <<
        ":" << (s - (s / 3600) * 3600 - ((s - (s / 3600) * 3600) / 60) * 60);
}
int main() {
    int seconds;
    std::cerr << "Enter the elapsed time in seconds ";
    std::cin >> seconds;
    GetTime(seconds);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS