Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Calendar Program - Offset days - C++

$
0
0
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:

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!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>