English 中文(简体)
月里的观点
原标题:View Years Alive in Months
  • 时间:2011-11-22 21:06:31
  •  标签:
  • c++
  • time

我正试图制定一项方案,查明他们有多少月活着,但还是有一些问题。 我迄今的职能是:

int getResult(int year, month, day, endResult)
{
    int thisYear, thisMonth, thisDay;

    year = thisYear - year;

    year *= 12;
}

我想要完成的工作将显示这样的产出:

Output: 
What year were you born? 
1989 
What month were you born? 
5 
What day were you born? 
23 
You are x months old.

我将持续几个月,但后来我认识到,如果他们出生的月份是在本月或之前的? 因此,如果任何人在计算方法上有任何倾向,我将不胜感激。

最佳回答

让我们看一看。 首先,现在可以说:

year_now and month_now

出生日期:

year_birth and month_birth

我们现在的情况是:

  • <代码>月_now=月_birth: 你已经计算出:

    months_old = (year_now-year_birth)*12
    
  • <代码>月_now >月_birth:易于:

    months_old = (year_now-year_birth)*12 + (month_now-month_birth)
    
  • <代码>月_now <月_birth:在这种情况下,(现今年份:birth)*12给予你更多必要的时间,并且你必须加以细分:

    months_old = (year_now-year_birth)*12 - (month_birth-month_now)
    

现在,如果你仔细研究,你就会看到,它们实际上都是相同的公式:

months_old = (year_now-year_birth)*12 + (month_now-month_birth)

(第三例,<代码>月_现月_birth为负数)

问题回答
months = (thisyear-years)*12+(thisMonth-months)
if(months < 0)
    System.out.println("Invalid info")
else{
    //DO YOUR THANG BRO 
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签