Day of week calculator off by 1 day

One of my class assignments is to create a program that calculates the day of the week by first calculating the Julian day number, adding one and doing a % 7 operation. I am told that days are numbered from 0 to 6, 0 being Sunday. When I enter today's date, I get "Thursday" - and today's Friday. My program appears to have calculated the Julian day number correctly.
Here's the line I think is causing the problem.
 
 int dayNum = ((long)JDN + 1) % 7;
Last edited on
I have no knowledge about julian day conversion, but does it have anything to do with this year being a leap year? Did you try a day prior to Feb. 29? I could be wrong, but that's the first thing that comes to my mind for this year.
What day of the week was Julian day zero? The answer to that question determines what you have to add to JDN before doing the modulus.

Another possible bug: how are you printing out the day of the week? Maybe you're setting dayNum correctly but printing the wrong string.
Topic archived. No new replies allowed.