Question 16. Program to calculate the current age of a person.

February 21, 2019
Question 16. Program to calculate the current age of a person.
// Programme to calculate the current age of a person.
#include "iostream"
using namespace std;
int main()
{
int DoA = 0, MoA = 0, YoA = 0; //Days, Moonths and Years of current age
int DoB = 0, MoB = 0, YoB = 0; //Days, Moonths and Years of birth
int Day = 0, Month = 0, Year = 0; //Days, Moonths and Years of current date
cout << "Enter the date of birth details";
cout << "\nEnter Day of Birth:";
cin >> DoB;
cout << "Enter Month of Birth:";
cin >> MoB;
cout << "Enter Year of Birth :";
cin >> YoB;
cout << "Enter the current date details";
cout << "\nEnter Day :";
cin >> Day;
cout << "Enter Month :";
cin >> Month;
cout << "Enter Year of :";
cin >> Year;
if(DoB<=Day) //True case of IF statement for checking days of age
{
DoA=Day-DoB;
}
else //False case of IF statement for checking days of age
if(Month==1 ||Month==3||Month==5||Month==7||Month==8||Month==10||Month==12)
{
Day=Day+31;
DoA=Day-DoB;
Month = Month-1;
}
else
if(Month==4||Month==6||Month==9||Month==11)
{
Day=Day+30;
DoA=Day-DoB;
Month = Month-1;
}
else
if(Month==2)
{
Day=Day+28;
DoA=Day-DoB;
Month = Month-1;
}
if(MoB<=Month) //True case of IF statement for checking Months of age
{
MoA=Month-MoB;
}
else //False case of IF statement for checking Months of age
{
Month=Month+12;
MoA=Month-MoB;
Year=Year-1;
}
YoA = Year-YoB; //Calculations of checking years of age
cout<< "\n Day of Age="<<DoA;
cout<< "\n Month of Age="<<MoA;
cout<< "\n Year of Age="<<YoA;
cout<< "\n";
return 0;
}

No comments:

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Powered by Blogger.