title: C++ Calendar (Cannot Get Value of Variable to Return to Main Function)
body: <p>Okay, so I have this project due for class by the 17th and I was wondering if I could get a bit of help. Basically, we are suppose to create a calendar that prints based on the day the Gregorian Calendar was created. I already figured out how to do the assignment but I am having trouble with leap year.</p>
  
  <p>What I am having a problem with is returning the value of offset back to the main function so it can be used in another function. Perhaps this is a bit too advanced for my skills but I feel like this should be something fairly easy to do.</p>
  
  <p>To give you an idea how leap year works. After the Century Offset does it's calculation, if the year is a leap year, it's suppose to subtract 1. Or in this case decrement. For some reason, the offset will not decrement for a leap year like 2016. If really confused as to why my if statement is not working. Can someone help?</p>
  
  <pre><code>//Write a program that will print a calendar for whatever year the user wants.
  
  //Declaring libraries...some I might not need....
  #include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  //Function prototypes
  void ComputeCalendar(string [], string [], int, int);
  void CenturyOffset(int year, int offset);
  const int DAYS_OF_THE_WEEK = 7;
  const int MONTHS_OF_THE_YEAR = 12;
  
  //function calls
  
  //Note: Use switch to calculate what day the calendar begins on
  
  //Determines what day that calendar begins on
  void CenturyOffset(int year, int offset){
      int c, y, z, s, d;
  
      c = year / 100;
      y = year % 100;
      z = y / 4;
      s = c + y + z;
      d = s % 7;
      offset = d;
      if (year % 4 == 0 &amp;&amp; year % 400 == 0)
          offset--;
      cout &lt;&lt; offset &lt;&lt; endl;
      }
  
  //function for creating the calendar
  void ComputeCalendar(string months[], string days[], int year, int offset) {
  
      cout &lt;&lt; "\n" &lt;&lt; setw(50) &lt;&lt; year &lt;&lt; "\n" &lt;&lt; endl;
      int cal;
      int week;
          for(cal=0; cal&lt;MONTHS_OF_THE_YEAR; cal++)
              {
                  cout &lt;&lt; "\n" &lt;&lt; endl;
                  cout &lt;&lt; setw(3) &lt;&lt; months[cal] &lt;&lt; " " &lt;&lt; year &lt;&lt; endl;
                  cout &lt;&lt; "\n" &lt;&lt; endl;
                      for(week=0; week&lt;DAYS_OF_THE_WEEK; week++)
                          {
                              cout &lt;&lt; setw(5) &lt;&lt; days[week];
                          }
                  cout &lt;&lt; endl;
              }
          }
  //Main function that allows the user to input the year they wish to see
  int main(int argc, char*argv[])
  {
      int year;
      int offset;
      cout &lt;&lt; "What year would you like to see the calendar for? \n" &lt;&lt; endl;
      cin &gt;&gt; year;
      cout &lt;&lt; "\n" &lt;&lt; endl;
  
          while(year &lt; 1754) //Check if the year was before or after 1754
              {
              cout &lt;&lt; "You may not enter a year that is before 1754. \n" &lt;&lt; endl;
              cout &lt;&lt; "Please enter another year." &lt;&lt; endl;
              cin &gt;&gt; year;
              cout &lt;&lt; "\n" &lt;&lt; endl;
              }
          string days[DAYS_OF_THE_WEEK] = {"SU","MO","TU","WE","TH","FR","SA"};             
  //Stores days of the week in an array
          string months[MONTHS_OF_THE_YEAR] = {"January", "February", "March",
                                    "April", "May", "June",
                                    "July", "August", "September",
                                    "October", "November", "December"}; 
  //Stores Months of the year in an array
          ComputeCalendar(months, days, year, offset);
          CenturyOffset(year, offset);
  }
  </code></pre>