Answer:
In C++
#include <iostream>
using namespace std;
int main(){
int days, hours, minutes, seconds;
cout<<"Total seconds: ";
cin>>seconds;
if(seconds>0){
days = seconds/86400;
seconds%=86400; ;
hours = seconds/3600;
seconds%=3600;
minutes = seconds/60;
seconds %=60;
cout<<days<<" days "<<hours<<" hours "<<minutes<<" minutes "<<seconds<<" seconds";}
else{ cout<<"Total seconds must be greater than zero"; }
return 0;}
Step-by-step explanation:
Declare all variables as integer
int days, hours, minutes, seconds;
Prompt for input
cout<<"Total seconds: ";
Get user inpur for seconds
cin>>seconds;
If input is greater than 0
if(seconds>0){
Calculate the number of days
days = seconds/86400;
Get the remaining seconds
seconds%=86400; ;
Calculate the number of hours
hours = seconds/3600;
Get the remaining seconds
seconds%=3600;
Calculate the number of minutes
minutes = seconds/60;
Get the remaining seconds
seconds %=60;
Print the required output
cout<<days<<" days "<<hours<<" hours "<<minutes<<" minutes "<<seconds<<" seconds";}
If seconds is less than 1, then it is invalid
else{ cout<<"Total seconds must be greater than zero"; }