Answer:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout<<"Enter time in seconds:";
int time, hour, minutes, seconds,initialTime;
cin>>time;
initialTime = time;
hour = floor(time / 3600);
time = time % 3600;
minutes = floor(time / 60);
time = time % 60;
seconds = time;
cout<< initialTime<<" can be broken down into: "<<endl;
cout<<hour << " hour(s)"<<endl;
cout<<minutes <<" minutes"<<endl;
cout<<seconds <<" seconds"<<endl;
return 0;
}
Explanation:
The programming language use is c++
The module cmath was called to allow me perform some math operations like floor division, and the Iostream allows me to print output to the screen. Using namespace std allows me to use classes from the function std.
I prompt the user to enter time in second, then declare all the variables that will be used which include time, hour, minutes, seconds and initialTime.
initialTime is used to hold the the time input entered by the user and will be printed at the end no arithmetic operation is carried out on it.
Floor division (returns the quotient in a division operation) and Modulo (returns the remainder in a division operation) division is used to evaluate the hours, the minutes and the seconds.
The final answers are then printed to the screen.
I have uploaded the c++ file and a picture of the code in action