Program to calculate age.
#include<iostream.h>
#include<conio.h>
struct date
{ int dd,mm,yyyy;
void get()
{
cout<<"Enter Date: (do not enter zero befor significant digit) ";
cin>>dd;
cout<<"Enter Month: (do not enter zero befor significant digit) ";
cin>>mm;
cout<<"Enter Year: (do not enter zero befor significant digit)";
cin>>yyyy;
}
void show()
{
cout<<endl<<yyyy<<" Years "<<mm<<" months "<<dd<<" days";
}
};
void calc(date a, date b)
{
date age;
if(b.dd>a.dd)
{
a.dd+=30;
a.mm--;
}
if(b.mm>a.yyyy)
{
a.mm+=12;
a.yyyy--;
}
age.dd=a.dd-b.dd;
age.mm=a.mm-b.mm;
age.yyyy=a.yyyy-b.yyyy;
cout<<"\nYour age is :\n";
age.show();
}
void main()
{
date dob,today;
cout<<"Enter today's date :\n";
today.get();
cout<<"\n\nEnter you date of birth:\n";
dob.get();
calc(today,dob);
getch();
}
No comments:
Post a Comment