Thursday 15 September 2011

C++: Getting the range between two months/years -


In class, we are doing assignments to get the range between two dates as input of months and years Are there.

My process code is as follows:

  int totalMonths1 = (year * MONTHS_IN_YEAR) + month; Integer climax 2 = (year 2 * MONTHS_IN_YEAR) + month 2; Int range; If (Kcalmoth 1 & gt; Total Mouth 2) {range = totalMonths1 - totalMonths2; } If (Kulmoth 1 and total number 2) {range = totalMonths2 - totalMonths1; }  

with const int MONTHS_IN_YEAR = 12

It tells me difference between two dates, but if I add result to 1, then this is the correct category according to my professor's example program, but I Want to know that instead of doing "difference + 1" is a better way to get the range.

No, none simpler / better than this a - b + 1 Unfortunately, nothing is more complicated and unnecessarily confused.


No comments:

Post a Comment