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

Write a program that converts time provided in seconds into a human readable for

ID: 3815738 • Letter: W

Question

Write a program that converts time provided in seconds into a human readable form. (Can you toll how long 238472352 seconds are?) The input and output should be exactly: Input time in seconds [USER ENTERS A NONNEGATIVE INTEGER] The time is X year(s), X day(s), X hour(s), X minute(s), and X second(s). For example, the output to an input of 61 is The time is 0 year(s), 0 day(s), 0 hour(s), 1 minute(s), and 1 second(s). and the output to an input of 3612 is The time is 0 year(s), 0 day(s), 1 hour(s), 0 minute(s), and 12 second(s). Assume no leap years, i.e., every year is exactly 365 days. Your program must work with inputs ranging from 0 seconds to 1000 years. Do not use floating-point numbers. You may not use staff. h. Name your file hrt.cpp. http://en.cppreference.com/w/cpp/language/types

Explanation / Answer

#include <iostream>
using namespace std;

int main()
{
    long long time;
    int years,days,hours,minutes,seconds;
   cout<<"Input time in seconds : ";
   cin>>time ;
   if(time <0)
   cout<<" Time should be non negative. Try again.";
   cin>>time;
  
   years = time /(365*24*60*60);
  
   time = time - (years*365*24*60*60); //time left after computing years
  
   cout<<time;
  
   days = time/(24*60*60);
  
   time = time - (days*24*60*60);//time left after computing days
  
   hours = time/(60*60);
  
   time = time - (hours*60*60); //time left after computing hours
  
   minutes = time/60;
  
   seconds = time - minutes*60;//time left after computing minutes is seconds
  
   cout<<" The time is "<<years<<" years "<<days<<" days "<<hours<<" hours "<<minutes <<" minutes "<<seconds <<" seconds.";
   return 0;
}


Output:

Input time in seconds :238472352

The time is 7 years 205 days 2 hours 19 minutes 12 seconds.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote