Calculate your age in CPP

This program will accept birthyear and birth month from the user and also accept the current year and current month, according to the given input this program will calculate the age of a person.

void main()
    {
    int bm,by;
    int cm,cy;
    int ay,am;
    clrscr();
    cout << "Birth Year (Exa : 1974) :";
    cin >> by;
    cout << "Birth Month (Exa : 7) :";
    cin >> bm;
    cout << "Current Month :";
    cin >> cm;
    cout << "Current Year(Exa: 2016):";
    cin >> cy;
    ay=cy-by;
    am=12-bm;
    cout << "You are now" << ay << "Years And" << am << "Months old";
    getch();
    }

Output:

Birth Year(Exa : 1974) :2001
Birth Month(Exa : 7) :3
Current Month :8
Current Year(Exa: 2016):2018 
You are now 17 Years And 9 Months old 

Leave a Reply