Program prints inconsistent day of week

My assignment is to create a program that calculates the day of the week for any given date. My book has instructed me to use the Julian day number, and has also given me directions on how to calculate it. I've checked my code against the book's algorithm, and I appear to be following the directions to a T (well, more or less). When I tried March 13th, the Julian day was correct but not the day of the week - but that subject has its own thread somewhere else on this forum. When I try my birthday, however, the Julian day calculation appears to be incorrect.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
double julianDayNumber(int month,int day,int year)
{
    long intRes1;
    if (year > 1582 || month > 10 || day > 15) {
        intRes1 = 2 - year / 100 + year / 400;
    }
    else {
        intRes1 = 0;
    }
    long intRes2 = static_cast<long>(365.25 * year);
    long intRes3 = static_cast<long>(30.6001 * (month + 1));
    double addition = intRes1 + intRes2 + intRes3 + 1720994.5;
    double JDN = addition + day;
    return JDN;
}

Note: "Julian day number" refers to the time system used in astronomy, not the day of the year.

Edit: Here is a link to the book's algorithm on Google Books: https://books.google.com/books?id=eHafXAo9v50C&printsec=frontcover&dq=c%2B%2B+programming+and+problem+solving+6th&hl=en&sa=X&ved=0ahUKEwifgdqJ89LLAhVQ4GMKHfiKCokQ6AEISDAE#v=onepage&q=julian%20day&f=false

Edit #2: After doing some research, the book's algorithm appears to be an adaptation (or, at least, attempt) of the algorithm given here:
http://mathforum.org/library/drmath/view/62338.html
Last edited on
Turns out it's the book's algorithm that's incorrect. According to the site to which I linked, there's a special rule for dates in January and February. Also, the 1720994.5 should be 1720995.
Topic archived. No new replies allowed.