【问题标题】:How to calculate the age of a person? [closed]如何计算一个人的年龄? [关闭]
【发布时间】:2013-05-16 06:55:49
【问题描述】:

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

【问题讨论】:

  • 你已经尝试了什么?
  • 是的,请阅读此处的文档。 msdn.microsoft.com/en-us/library/vstudio/… - 查看函数名称以获得一些提示。另外,考虑倒退问题。即找出如何从特定结果返回特定输入。 (对于不熟悉的主题,这可能是浏览帮助文档的最快方式)
  • 不,没有想法。我认为这是一个 NP Hard 问题。

标签: c++ visual-c++ time


【解决方案1】:

希望对你有帮助....

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

【讨论】:

    猜你喜欢
    • 2010-10-01
    • 1970-01-01
    • 2013-07-24
    • 2013-10-28
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    相关资源
    最近更新 更多