1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include<iostream>
#include<cmath>
#include<ctime>
using namespace std;
int main()
{
int todayDay, todayMonth, todayYear;
int birthDay, birthMonth, birthYear;
int birthHour, birthMin, birthSec;
int hour, min, sec;
int ageDay, ageMonth, ageYear;
int ageHour, ageMin, ageSec;
time_t result;
result = time(NULL);
struct tm* tp = localtime(&result);
todayMonth = tp->tm_mon + 1;
todayDay = tp->tm_mday;
todayYear = tp->tm_year + 1900;
hour = tp->tm_hour;
min = tp->tm_min;
sec = tp->tm_sec;
cout << "Today's Date is: "<< todayMonth <<" " << todayDay <<" "<< todayYear <<endl;
cout << "And the time is: "<< hour <<":"<< min << ":" << sec << endl;
cout << "Enter month of your birth: "<<endl;
cin >> birthMonth;
cout << "Enter the date of birth: "<<endl;
cin >> birthDay;
cout << "Enter the birth year: "<<endl;
cin >> birthYear;
cout << "Enter the time you were born. ";
cout << "\nHour, minute, and second seperated by spaces." <<endl;
cin >> birthHour >> birthMin >> birthSec;
if(birthYear <= 1900)
{
ageYear = todayYear - birthYear;
}
if(birthDay <= 31)
{
ageDay = todayDay - birthDay;
}
if(birthMonth <= 12)
{
ageMonth = todayMonth - birthMonth;
}
if (birthHour <= 24)
{
ageHour = hour - birthHour;
}
if (birthMin < 60)
{
ageMin = min - birthMin;
}
if(birthSec < 60)
{
ageSec = sec - birthSec;
}
cout << "Your age is: "
<< ageMonth << " month(s) and "
<< ageDay << " day(s)." << endl
<< ageHour << " hour(s) "
<< ageMin << " min(s) "
<< ageSec << " second(s)."<< endl;
system("pause");
return 0;
}
|