Answer to Question #23076 in C++ for ZEESHANTARIQ

Question #23076
hello sir, i need a program in c++ i.e
A program in c++ that input your age,convert it to month,days,hours,minutes&seconds and print all these values on screen.
1
Expert's answer
2013-01-29T08:50:22-0500
#include <iostream>
using namespace std;

int main ()
{
cout<<"Enter your age, please (in seconds)\n";
long long s;
cin>>s;
int age = (s - (s % 31104000)) / 31104000;
s = s % 31104000;
int month = (s - (s % 2592000)) / 2592000;
s = s % 2592000;
int& days = (s - (s % 86400)) / 86400;
s = s % 86400;
int hour = (s - (s % 3600)) / 3600;
s = s % 3600;
int minutes = (s - (s % 60)) / 60;
s = s % 60;

cout<< "You're alive: "<< age << " years\n "<< month << " month\n " <<days << " days\n"<< hour << " hours\n" << minutes << " minutes\n" << s << " seconds\n";

system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS