如何计算一个人的年龄

How to calculate the age of a person?

本文关键字:一个人的年 计算 何计算      更新时间:2023-10-16

例如,我需要计算从1996-11-03 (yy/mm/dd)到现在的时间。我需要做的MC visual c++在windows窗体应用程序。用户将输入年,月,日在3个不同的文本框'。什么好主意吗?

可能会对你有所帮助....

 #include<iostream>
    using namespace std;
    int main()
    {
        system("TITLE how old are you?");
        system("color f3");
        int yearnow,yearthen,monthnow,monththen,age1,age2;
        cout<<"tttEnter the current year and month nttt(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<<"nntttYou are "<<age1<<" year and "<<age2<<" moth old";
        system("pause>>void");
    }