1. Design a C++ program to convert seconds to a concise representation way: x ho
ID: 3748466 • Letter: 1
Question
1. Design a C++ program to convert seconds to a concise representation way: x hours y minutes z seconds. Input an integer that represents a length of time in seconds. The program should then output the number of hours, minutes, and seconds that corresponds to that number of seconds. For example, if the user inputs 50391 total seconds, then the program should output 13 hours, 59 minutes, and 51 seconds. (13*3600+59*60+51 = 50391) Hint: you might consider modulus (%) operator to solve the problem.
Explanation / Answer
#include <iostream>
using namespace std;
void convertSeconds(int seconds) {
int hours = 0;
int mins = 0;
int sec = 0;
int time=seconds;
hours = time/3600;
time = time%3600;
mins = time/60;
time = time%60;
sec = time;
// printing data to user
cout<<hours<<" hour(s) "<<mins<<" minute(s) and "<<sec<<" second(s) ";
}
int main(){
convertSeconds(3671);
convertSeconds(3738);
return 0;
}
/*output:
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.