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;
void convertTime(int seconds);
int main(){
int seconds;
cout<<"Enter time for an event in seconds: ";
cin>>seconds;
convertTime(seconds);
cin>>seconds;
}
void convertTime(int seconds){
int hours = 0;
int minutes = 0;
int second = 0;
hours = seconds/3600;
seconds = seconds%3600;
minutes = seconds/60;
seconds = seconds%60;
second = seconds;
cout<<hours<<":"<<minutes<<":"<<second<<"\n";
}
Comments
Leave a comment