153k views
2 votes
Write a C11 program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (For example, if the elapsed time is 9,630 seconds, then the output is 2:40:30.)

User Unfrev
by
4.9k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

#include <iostream>

using namespace std;

int main()

{

int secondsElapsed, hours, minutes, seconds;

const int secondsPerMinute = 60;

const int secondsPerHour = 60 * secondsPerMinute;

cout << "Please enter the number of seconds elapsed: ";

cin >> secondsElapsed;

hours = secondsElapsed / secondsPerHour;

secondsElapsed = secondsElapsed % secondsPerHour;

minutes = secondsElapsed / secondsPerMinute;

seconds = secondsElapsed % secondsPerMinute;

cout << hours << ":" << minutes << ":" << seconds << endl;

return 0;

}

User Joshaven Potter
by
5.2k points