title: Project Euler #19
body: <p>Warning! Spoilers ahead!</p>
  
  <blockquote>
    <p>You are given the following information, but you may prefer to do some
    research for yourself.</p>
    
    <p>1 Jan 1900 was a Monday.
    Thirty days has September,
    April, June and November.
    All the rest have thirty-one,
    Saving February alone,
    Which has twenty-eight, rain or shine.
    And on leap years, twenty-nine.</p>
    
    <p>A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400. How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?</p>
  </blockquote>
  
  <p>At first, it seems like a simple problem. However, as I coded the solution, I ran into an odd problem - the answer should, in fact, be 171, but I get 173, whatever I do. I've looked over and over again my code, but nevertheless cannot find the bug.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main () {
  
      int count = 0, days_in_month, days_passed = 1;
  
      for (int i = 1900; i &lt;= 2000; i++) {
          for (int j = 1; j &lt;= 12; j++) {
              if (j == 4 || j == 6 || j == 9 || j == 11) {
                  days_in_month = 30;
              } else if (j == 2) {
                  if (i % 400 == 0 || (i % 4 == 0 &amp;&amp; i % 100 != 0)) {
                      days_in_month = 29;
                  } else {
                      days_in_month = 28;
                  }
              } else {
                  days_in_month = 31;
              }
              if (days_passed % 7 == 0) {
                  count++;
              }
              days_passed += days_in_month;
          }
      }
  
      cout &lt;&lt; count &lt;&lt; endl;
  
      cin.ignore();
      return 0;
  
  }
  </code></pre>
  
  <p>Can anyone notice anything wrong with my code?</p>