Write a C++ Program to make a age calculator to calculate the age of two persons that will ask first person to enter date of birth and second to enter age,the date kf birth will be in format of dd/mm/yy when it will enter the age like my dob is 8/8/2002 I'm 18 it has to show you're 18 and elder than second person..it also has to show that who is elder who is younger for example first person is 18 and second is 17 it has to show first person is elder second is younger also tell the age difference in dd/mm/yy format for example first person is 18 years 9 months 7 days elder second is 17 years 4 months 15 days younger also tell how many years it is younger one year two year e.t.c
#include <iostream>
using namespace std;
int main(){
int dd, mm, yy, age;
char c;
cout<<"Enter date of birth of person 1: ";
cin>>dd; cin>>c; cin>>mm; cin>>c; cin>>yy;
cout<<"Enter age of person 2: ";
cin>>age;
if(2021 - yy > age) cout<<"Person 1 is older than person 2 by "<<2021 - yy - age<<" years "<<mm<<" months and "<<dd<<" days.";
else{
dd = 31 - dd;
mm = 12 - mm;
yy = age - (2021 - yy) - 1;
if(yy < 0) yy = 0;
cout<<"Person 2 is older than person 1 by "<<yy<<" years "<<mm<<" months and "<<dd<<" days."<<endl;
}
return 0;
}
Comments
Leave a comment