Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Coding Your program will make use of long long int variables for all calcula

ID: 3873447 • Letter: C

Question

C++ Coding

Your program will make use of long long int variables for all calculations. Note: the use of long long int requires that you have ++11 support. You should have this automatically if you are using a newer version of Visual Studio. The support is there for GCC as well, but you may need the -std-c++11 or -std-c++0x compiler flag. You first need to read in the total number of seconds. Your should then output this value as follows: Total seconds: xxx Where xxx is the number of seconds you read in. If this value is O or less you need to output the message Total seconds must be greater than zero For example, assume the input is: 102 The output will be as follows: Total seconds: -102 Total seconds must be greater than zero If the number is more than zero you need to calculate the number of days, hours, minutes and seconds. The value for hours should be after you have subtracted off the number of days. The value for minutes will be the number of minutes after you have subtracted the days and hours. Seconds will be the remainder after you have subtracted the days, hours and minutes You should only output the days if the number of days is more than 0. You should only output the hours if the number of hours is more than 0. You should only output the minutes if the number of minutes is more than 0 and you should only output the seconds if the number of seconds is greater than 0 For example, assume the input is: 90061

Explanation / Answer

The below code satisfies the given requirement as follows:-

-------------------------------------------------------------------------------

#include <iostream>

using namespace std;

int main()

{

long int seconds, minutes, hours, days,h, secs_remine, mins_remine;

cout<<"Enter number of seconds: ";

cin>>seconds;

hours = seconds / 3600;

days=hours/24;

h=(hours)-(days*24);

minutes = seconds / 60;

mins_remine = minutes % 60;

secs_remine = seconds % 60;

if (seconds < 0)

{

cout<<"Total Seconds : "<<seconds<<" ";

cout<<"Total seconds must be greater than zero";

}

else

{

cout<<"Total Seconds : "<<seconds<<" ";

if(days!=0)

cout<<days<<" day(s) ";

if(h!=0)

cout<<h<<" hour(s) ";

if(mins_remine!=0)

cout<<mins_remine<<" minute(s) ";

if(secs_remine!=0)

cout<<secs_remine<<" second(s) ";

}

return 0;

}

Output 1:-

--------

Enter number of seconds: -102

Total Seconds :-102

Total seconds must be greater than zero

Output 2:-

--------

Enter number of seconds: 90061

Total Seconds : 90061

1 day(s)

1 hour(s)

1 minute(s)

1 second(s)

output 3:-

-----------

Enter number of seconds: 36011

Total Seconds : 36011

10 hour(s)

11 second(s)