So for my class, I had to write a fully functional Calendar program (in C++). The program itself works without any errors. Although to determine the offset of days for each month automatically, this was a function I was given:
I understand how the math on the return line works, I just hoping somebody could explain to me what the numbers in the array are for/what they mean and what that 'year -= month < 3;' line is doing...
Thanks!
int determineOffset (int year, int month) {
const int TN[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
year -= month < 3;
return (year + year/4 - year/100 + year/400 + TN[month-1] + 1) % 7;
}
I understand how the math on the return line works, I just hoping somebody could explain to me what the numbers in the array are for/what they mean and what that 'year -= month < 3;' line is doing...
Thanks!