title: In C++, using a loop to find the # of days on any given date?
body: <p>And yes this is an assignment-- So please don't post solutions, but detailed pseudocodes are extremely helpful!</p>
  
  <p>I already have a program in C++ that accepts a date from the user and will determine if it is a leap year or not.</p>
  
  <p>Here is my leap year function so far (I do hope that this is the correct logic):</p>
  
  <pre><code>bool isLeapYear (int year){
      int leapYear = 0;
  
      //leapyear = 1 when true, = 0 when false
      if ((year%400 == 0) &amp;&amp; (year%100 != 100)) {
          leapYear = 1;
          }
      else if (year%4 == 0) {
          leapYear = 1;
          }
      else {
          leapYear = 0;
          }
  
  
  
      if (leapYear == 1) {
          return 1;
      }
      else {
          return 0;
      }     
  }
  </code></pre>
  
  <p>Here is a paraphrase of what I must do next:</p>
  
  <blockquote>
    <p>You MUST use a loop that adds months one at a time to an accumulated sum.
    Don't use any hardcoded values 
    Such as 152 for the first 5 months in a leap year</p>
  </blockquote>
  
  <p>And to clarify, this is my first programming class and have been in this C++ class for just about a month now.
  So it would be greatly appreciated if anyone could help me figure out how to do the loop statements to add the number of the months?
  (IE: 12/31/2013 should be "365" in a non leap year, and "366" in a leap year).</p>
  
  <p>I know this is wrong but this is what I have so far for a function "dayNumber" that simply return the number of days in the year to the main function (which is calling the dayNumber function):</p>
  
  <pre><code>int dayNumber (int day, int month, int year){
      //variable declarations
      int sumTotal = 0;
  
  
      for ( int loop = 1; loop &lt; month; loop++) {
          sumTotal = (( month-1 ) * 31);
          sumTotal = sumTotal + day + 1;
          if ( (loop==4) || (loop=6) || (loop=9) ||
              (loop==11) ) {
              sumTotal = ( sumTotal - 1 );
          }
          else if ( isLeapYear(year) == 1 ) {
              sumTotal = (sumTotal - 2);
          }
          else  {
              sumTotal = (sumTotal - 3);
          }
  
      }
  
  
      return sumTotal;
  }
  </code></pre>
  
  <p>I started to mess around with it to get to a proper value for days I knew but it kind of messed it up more, haha.</p>
  
  <p>If anyone has any guidance on how to appropriately do a loop, I would be extremely greatful!:) </p>
  
  <p><P><BR><P><BR><P></p>
  
  <p><strong>EDIT:
  Alright, I think I may have answered my own question.</strong></p>
  
  <blockquote>
    <p>int dayNumber (int day, int month, int year){
       //variable declarations
       int sumTotal = 0;</p>
    
    <p>for ( int loop = 1; loop &lt; month; loop++) {
           sumTotal = ( sumTotal + 31 );</p>
  
  <pre><code>   if ( (loop==4) || (loop==6) || (loop==9) ||
         (loop==11) ) {
         sumTotal = ( sumTotal - 1 );
     }
  </code></pre>
    
    <p>}
       if ((month !=2) &amp;&amp; (month > 1)) {
           if (isLeapYear(year) ==1) {
               sumTotal = ( sumTotal - 2 );
           }
           else {
               sumTotal = ( sumTotal - 3);
           }
       }</p>
    
    <p>else {
           sumTotal = sumTotal;
       }
       sumTotal = sumTotal + day;</p>
    
    <p>return sumTotal;
    }</p>
  </blockquote>
  
  <p>I definitely need to work on my loops. 
  I appreciate letting me know that my '=' should have been '=='! </p>
  
  <p>I believe this is an appropriate code using a simple enough loop? 
  I will test some more dates. I've only tested the few provided on the class site so far. </p>
  
  <p><strong>I can't answer my own posts, I don't have enough reputation.</strong></p>