How to calculate a person's age?

For example, I need to calculate the time elapsed from 1996-11-03 (yyy / mm / dd) until now. I need to do this in MC visual C ++ in a Windows Form application. The user enters the year, month, day in 3 different texbox'es. Any ideas?

-7


source to share


1 answer


maybe this will help you ....



 #include<iostream>
    using namespace std;

    int main()
    {
        system("TITLE how old are you?");
        system("color f3");
        int yearnow,yearthen,monthnow,monththen,age1,age2;

        cout<<"\t\t\tEnter the current year and month \n\t\t\t(eg. 1997, enter, 7, enter):\n ";
        cin>>yearnow;
        cin>>monthnow;
        cout<<"Enter your birthyear and month: \n";
        cin>>yearthen;
        cin>>monththen;

        if(monththen >12 || monththen<1)
            return 1;

        if(monththen > monthnow){
             age1=yearnow-yearthen-1;
             age2=(12-monththen) + monthnow;
        }else{
             age1=yearnow-yearthen;
             age2=12-monththen;
        }
        cout<<"\n\n\t\t\tYou are "<<age1<<" year and "<<age2<<" moth old";
        system("pause>>void");
    }

      

+1


source







All Articles