Switch to full style
Codes, tips and tricks,discussions and solutions related to C#
Post a reply

Know Your Age

Mon May 21, 2007 11:10 pm

Program that make u know your age by input your birth day(get your age from birth-date code c++).
cpp code
#include<iostream>
using namespace std;
class AgeGetter
{
private:
int day;
int month;
int year;
public:
AgeGetter():day(1), month(1), year(1)
{}
void enterBirthdate()
{
cout<<"Get your age from birthdate:";
cout<<endl;
cout<<"Now you have to enter your birthdate";
cout<<endl;
cout<<"day(dd):";
cin>>day;
cout<<"month(mm):";
cin>>month;
cout<<"year(yyyy):";
cin>>year;
cout<<endl;
}
void Calculate_age(AgeGetter a1, AgeGetter a2)
{
if(a1.day>a2.day && a1.month>a2.month)
{
cout<<"your age is :"<<endl;
cout<<"\t\t"<<a1.day-a2.day<<"-"<<a1.month-a2.month<<"-"<<a1.year-a2.year;
cout<<endl<<endl;
}
else if(a1.day<a2.day && a1.month>a2.month)
{
cout<<"your age is :"<<endl;
cout<<"\t\t"<<(a1.day+30)-a2.day<<"-"<<(a1.month-1)-a2.month<<"-"<<a1.year-a2.year;?
cout<<endl<<endl;
}
else if(a1.day>a2.day && a1.month<a2.month)
{
cout<<"your age is :"<<endl;
cout<<"\t\t"<<a1.day-a2.day<<"-"<<(a1.month+12)-a2.month<<"-"<<(a1.year-1)-a2.year;
cout<<endl<<endl;
}
else if(a1.day<a2.day && a1.month<a2.month)
{
cout<<"your age is :"<<endl;
cout<<"\t\t"<<(a1.day+30)-a2.day<<"-"<<(a1.month+11)-a2.month<<"-"<<(a1.year-1)-a2.year;
cout<<endl<<endl;
}
else if(a1.year<a2.year)
{
cout<<"The birthdate you have entered is invalid."<<endl;
}
}
};
int main()
{
AgeGetter a1, a2, a3;
cout<<"\t Entry Today date: ";
cout<<endl<<endl;
a1.enterBirthdate();
cout<<endl<<endl;
a2.enterBirthdate();
a3.Calculate_age(a1,a2);
return 0;
}




Re: Know Your Age

Sat Jun 09, 2007 1:52 pm

Thanks General for your efforts.

Post a reply