this program contains everything even leap year: :idea:
i am a beginner in cpp (we have this in school so i am learning this age 15 )

# include<iostream.h>
# include<conio.h>

void main (void)

{


	clrscr();

	int years1, months1, days1;
	int monthdays1[12] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
	int startday;
	int years2, months2, days2;
	int endday;
	int leapdays1, leapdays2;
	int oldyears, agebalance, balancedays, oldmonths, olddays, i;

	int const BASEYEAR=1900;
	int const BASEMONTH=12;
	int const BASEDAY=31;

	//Input birth date

	cout<<"Enter the date you were born(dd mm yyyy):\t";
	cin>>days1>>months1>>years1;
	cout<<endl;

	//error
	if (years1<BASEYEAR)
	 {
	 cout<<"The value of year is below 1900 Press any key to continue";
	 getch();
	 return;
	 }
		if (months1>BASEMONTH)
	 {
	 cout<<"The value of months is above 12 Press any key to continue";
	 getch();
	 return;
	 }

		if (days1>BASEDAY)
	 {
	 cout<<"The value of days is above 31 Press any key to continue";
	 getch();
	 return;
	 }

	//input todays date

	cout<<"Enter the date today(dd mm yyyy):\t";
	cin>>days2>>months2>>years2;
	cout<<endl;

	//error
	if (years2<BASEYEAR)
	 {
	 cout<<"The value of years is below 1900 Press any key to continue";
	 getch();
	 return;
	 }
		if (months2>BASEMONTH)
	 {
	 cout<<"The value of months is above 12 Press any key to continue";
	 getch();
	 return;
	 }

		if (days2>BASEDAY)
	 {
	 cout<<"The value of days is above 31 Press any key to continue";
	 getch();
	 return;
	 }

	//calculation
	years1=years1-1;
	months1=months1-1;
	days1=days1;

	leapdays1=years1/4;  //leapyear is a multiple for 4
	if((months1>=2) && ((years1+1)%4==0)) leapdays1++;
	if(years1>1999) leapdays1--;      //2000 is no leapyear


	startday=(years1*365)+monthdays1[months1-1]+days1+leapdays1;

	years2=years2-1;
	months2=months2-1;
	days2=days2;

	leapdays2=years2/4; //leapyear is a multiple for 4

	if((months2>=2) && ((years2+1)%4==0)) leapdays2++;
	if(years2>1999) leapdays2--; //2000 is no leapyear


	endday=(years2*365)+monthdays1[months2-1]+days2+leapdays2;

	agebalance=endday-startday;
	oldyears=agebalance/365;
	balancedays=agebalance%365;
	i=0;
	while (balancedays> monthdays1[i])
		{
		i++;
		}
	oldmonths=i;

	olddays=balancedays-monthdays1[oldmonths-1];

	//output
	cout<<"Your age is "<<oldyears<<" years, "<<oldmonths<<" months, ";
	cout<<olddays<<" days"<<endl;
	getch();
}

<< moderator edit: added [code][/code] tags >>

if(years1>1999) leapdays1--;      //2000 is no leapyear

2000 was a leap year.

hmmmm...
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.