im trying to write a program where a user inputs a date and the day of the week is then printed to the screen. so 3/4/2009 would print friday
im using Zeller's congruence (Zeller's congruence - Wikipedia, the free encyclopedia) but it doesnt seem to give the correct result. here's my maths.
then if statements to print out the days with 0 = sat, 1 = sun ... 6 = fri.Code:q = DD; // DD is day entered by the user m = MM; // MM is the month entered by the user m = ( (m+1) * 26 ) / 10; K = YYYY % 100; // YYYY is the year entered by the user KK = K / 4; J = YYYY / 100; JJ = J / 4; DayOfTheWeek = q + m + K + KK + JJ - (2*J); DayOfTheWeek = DayOfTheWeek % 7;
it doesnt work for some days eg 1/1/1700 was a friday, but my program will say it is a wednesday. ive tried the other formulae on the wiki page, like changing the -2J to +5j, but doesnt change anything. get the same errors
but it does work for many days, which is why i think the problem may just be something minor
so i was wondering if some fresh eyes could spot the flaw that i cant pick up. thx