adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C++ to Calculate Age

Program in C++ to Calculate Age  

#include<iostream>
#include<conio.h>
 using namespace std;
  int main()
   {
      int y,m,d,td,pd,tm,pm,ty,py;
      cout<<"Enter Previous  Day, Month and Year:-";
      cin>>pd>>pm>>py;
      cout<<"Enter today Day , Month and Year:-";
      cin>>td>>tm>>ty;
      int mm[12]={31,py%4==0&&py%100!=0||py%400==0?29:28,31,30,31,30,31,31,30,31,30,31};
      if(pd>td)   //For Dates
       {
           td=td+mm[tm-2];
           d=td-pd;
           tm=tm-1;
       }
      else
         d=td-pd;
      if(pm>tm)   //For Months
        {
          tm=tm+12;
          ty=ty-1;
          m=tm-pm;
        }
      else
         m=tm-pm;
         y=ty-py;    //For Years

     cout<<"\nAge is "<<y<<" Years "<<m<<" Months and "<<d<<" Days.";
     return 0;
  }


Output:-
    


Post a Comment

3 Comments

leather said…
To Fluency shows you how to learn English in the most effective way so that you can become fluent, as fast as possible. Are you ready to speak English Fluently?
Anonymous said…
But output shi nhi h