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 83 84 85 86 87 88
|
#include <cstdlib>
#include <iostream>
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <unistd.h>
#include <conio.h>
#include <time.h>
#include <ctime>
using namespace std;
void getCurrentDate(int&, int&, int&);
void getBirthday(int&, int&, int&);
int calcYears(int, int, int, int, int, int);
int main()
{
int month, day, year, month1, day1, year1, age;
getCurrentDate(month1, day1, year1);
getBirthday(month, day, year);
age = calcYears(year, year1, month, month1, day, day1);
cout << age;
//cout << "\t" << month << "\t" << day << "\t" << year << endl;
//cout << "\t" << month1 << "\t" << day1 << "\t" <<year1 << endl;
system("pause");
return 0;
}
void getBirthday(int& month, int& day, int& year)
{
cout << "\nEnter the month you were born on: ";
cin >> month;
cout << "\nEnter the day you were born: ";
cin >> day;
cout << "\nEnter the year you were born: ";
cin >> year;
cout << endl;
return;
}
void getCurrentDate(int& month1, int& day1, int& year1)
{
time_t t = time(NULL);
tm* timePtr = localtime(&t);
// cout << "seconds= " << timePtr->tm_sec << endl;
// cout << "minutes = " << timePtr->tm_min << endl;
// cout << "hours = " << timePtr->tm_hour << endl;
// cout << "day of month = " << timePtr->tm_mday << endl;
// cout << "month of year = " << timePtr->tm_mon << endl;
// cout << "year = " << timePtr->tm_year + 1900 << endl;
// cout << "weekday = " << timePtr->tm_wday << endl;
// cout << "day of year = " << timePtr->tm_yday << endl;
// cout << "daylight savings = " << timePtr->tm_isdst << endl;
int year1= timePtr->tm_year + 1900;
int month1= timePtr->tm_mon + 1;
int day1= timePtr->tm_mday;
// cout << "\nEnter the current month: ";
// cin >> month1;
// cout << "\nEnter the current day: ";
// cin >> day1;
// cout << "\nEnter the current year: ";
// cin >> year1;
// cout << endl;
return;
}
int calcYears(int year, int year1, int month, int month1, int day, int day1)
{
int years;
years = year1 - year;
if ((month > month1) || ( month == month1 && day > day1))
years = years - 1;
return years;
printf("\n");
}
|