本文介绍了如何计算一个人的年龄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我需要计算从 1996-11-03 (yy/mm/dd) 到现在的时间.我需要在 Windows 窗体应用程序中的 MC Visual C++ 中执行此操作.用户将在 3 个不同的 texbox'es 中输入年、月、日.有什么想法吗?

For example, I need to calculate the time past since 1996-11-03 (yy/mm/dd) until now.I need to do it in MC visual c++ in windows form app. The user will enter the year, month, day in 3 different texbox'es. Any ideas?

推荐答案

愿这对你有帮助....

may 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");
    }

这篇关于如何计算一个人的年龄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 21:58