c++ day of week for given date
<p>I am trying to write a simple program in c++ that returns the day of the week for a given date. </p>

<p>The input format is day, month, year. I cannot get it to work with leap years. I tried subtracting one from the <code>a</code> variable when the input year is a leap year, but the program just ends up crashing without an error message. </p>

<p>I would appreciate any suggestions, but please try to remain simple, I am still a beginner. Apologies for the stupid question, and please excuse my mistakes, this is the first time I post on this site.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;
using namespace std;


int d;
int m;
int y;


string weekday(int d, int m, int y){
    int LeapYears = (int) y/ 4;
    long a = (y - LeapYears)*365 + LeapYears * 366;
    if(m &gt;= 2) a += 31;
    if(m &gt;= 3 &amp;&amp; (int)y/4 == y/4) a += 29;
    else if(m &gt;= 3) a += 28;
    if(m &gt;= 4) a += 31;
    if(m &gt;= 5) a += 30;
    if(m &gt;= 6) a += 31;
    if(m &gt;= 7) a += 30;
    if(m &gt;= 8) a += 31;
    if(m &gt;= 9) a += 31;
    if(m &gt;= 10) a += 30;
    if(m &gt;= 11) a += 31;
    if(m == 12) a += 30;
    a += d;
    int b = (a - 2)  % 7;
    switch (b){
    case 1:
        return "Monday";
    case 2:
        return "Tuesday";
    case 3:
        return "Wednesday";
    case 4:
        return "Thursday";
    case 5:
        return "Friday";
    case 6:
        return "Saturday";
    case 7:
        return "Sunday";
    }
}

int main(){
    cin &gt;&gt; d &gt;&gt; m &gt;&gt; y;
    cout &lt;&lt; weekday(d, m, y);
}
</code></pre>