title: program that determines day number tips
body: <p>I'm trying to write a c program that determines the day number (1 to 366) in a year for a date provided by a user.
  How do I adjust this program for a leap year like (december 31,2012) is day 366 since it was a leap year. This is my code so far. Im thinking I need an if staement before switch but I dont know how to implement please help</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int isleap(int year);
  
  void  displaydate(int month ,int date ,int year,int daynumber);
  
  int main (void) {
  
      int month;
      int day;
      int year;
      int leapyear;
      int daynumber;
  
      printf(" enter a month");
      scanf("%d",&amp;month);
  
      printf(" enter a day");
      scanf("%d",&amp;day);
  
      printf(" enter a year");
      scanf("%d",&amp;year);
  
      leapyear= isleap( year);
  
      displaydate( month,day,year,daynumber);
  
      daynumber = leapyear &amp;&amp; month &gt; 2 ? day+1 : day;
  
      switch(month) {
  
          case 1 : daynumber = day;
                  break;
  
          case 2 : daynumber = 31 + day;
                  break;
  
          case 3 : daynumber = 59 + day + 1; 
                  break;
  
          case 4 : daynumber = 89 + day;
                  break;  
  
          case 5 : daynumber = 120 + day;
                  break;  
  
          case 6 : daynumber = 150 + day;
                  break; 
  
          case 7 : daynumber = 181 + day;
                  break;  
  
          case 8 : daynumber = 212 + day;
                  break;   
  
          case 9 : daynumber = 232 + day;
                  break;  
  
          case 10 : daynumber = 263 + day;
                  break;  
  
          case 11 : daynumber = 293 + day;
                  break;  
  
          case 12 : daynumber = 324 + day;
                  break;
  
          default:
                  break;
      }
  
      return 0;
  }
  
  int isleap(int year)
  {
      if (((year % 4 == 0) &amp;&amp; (year % 100!= 0)) || (year%400 == 0)) {
          printf("%d  1", year);
          return 1;
      }
      else {
          printf("%d 0", year);
          return 0; 
      }
  }
  
  void  displaydate(int month ,int date ,int year,int daynumber)
  { 
      printf("\n your date is %d and the day number is %d",month,date,year,daynumber);
  
  }
  </code></pre>