title: c++ calendar program format, display, offset
body: <p>I am writing a program in c++ that will print a calendar for the entire year. The program will ask the user what year they want to enter so it may determine if it is a leap year. It will then ask the user to ask what day would they want they January 1<sup>st</sup> to start counting from. It should then cout every single day of January and then move to February then count every single day then move on to march etc. However it does not print every month correctly. I also am required to not use the <code>%</code> operator. Any help that could make my program print a proper calendar would be much appreciated and please do not post suggestions that use the <code>%</code> operator.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;iomanip&gt;
  using namespace std;
  /****************************************************************************************
                               Prototypes
  ****************************************************************************************/
  void getyear(int&amp; year , int&amp; days_per_yr);
  void list_months(int imonth, int iyear);
  void firstday(int&amp; mostart);
  void start_month(int&amp; mostart);
  int get_numdays(int xmonth, int numdays, int year);
  void listdays(int numdays, int&amp; mostart);
  bool isLeapYear(int year);
  void printMonth();
  /****************************************************************************************
                             Main
  ****************************************************************************************/
  int main(){    
  printMonth();
  }
  
  void printMonth(){ // calls all the functions needed to print the calendar
      int year;
      int day;
      int month;
      int mostart;
      int days_per_yr; 
      int numdays; // number of days per month is stored here
      cout &lt;&lt; "What year do you want a calendar for? ";
      getyear(year, days_per_yr);   
      cout &lt;&lt; "What day of the week does January 1 fall ";
      cout &lt;&lt;"on (0 for Sunday, 1 for Monday, etc.)? ";
      firstday(mostart);
      cout &lt;&lt; year &lt;&lt; "\n" &lt;&lt;endl;
      for (month=1; month &lt;= 12; ++month){
      list_months(month, year);
      start_month(mostart);
      numdays=get_numdays(month, numdays, year);
      listdays(numdays, mostart);
      }
  }
  
  
  
  
  
  
  
  void getyear(int&amp; year, int&amp; days_per_yr){ //gets the year from the user and sends it back to the printMonth function
                           // this function is vital for the isLeapyear function to work properly
      cin &gt;&gt; year;
      if (isLeapYear(year) == true){
      days_per_yr = 366;}
      else{
      days_per_yr = 365;}
  }
  
  
  
  
  
  
  
  
  void list_months(int imonth, int iyear){ // lists every month needed with the days spaced out correctly
      switch (imonth){
      case 1: cout&lt;&lt; "        January" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"-----------------------"&lt;&lt; endl;
      break;
      case 2: cout&lt;&lt; "        Febuarry" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"-----------------------"&lt;&lt; endl;
      break;
      case 3: cout&lt;&lt; "        March" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 4: cout&lt;&lt; "        April" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 5: cout&lt;&lt; "        May" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 6: cout&lt;&lt; "        June" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 7: cout&lt;&lt; "        July" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 8: cout&lt;&lt; "        August" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 9: cout&lt;&lt; "        September" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 10: cout&lt;&lt; "        October" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 11: cout&lt;&lt; "        November" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      case 12: cout&lt;&lt; "        December" &lt;&lt; endl;
      cout &lt;&lt; "  S  M  T  W  T  F  S  "&lt;&lt; endl;
      cout &lt;&lt;"------------------------"&lt;&lt; endl;
      break;
      }
  }
  
  
  
  
  
  
  void firstday(int&amp; mostart){ // gets the input from the user for the start_month(); function
  
      cin &gt;&gt; mostart;
      cout &lt;&lt;"\n";
      }
  
  
  
  
  
  
  void start_month(int&amp; mostart){ //does the spacing so that the desired day entered by the user is displayed correctly
  
      if(mostart==0){
       cout &lt;&lt; setw(3);
       }
       else if (mostart == 1){
       cout &lt;&lt; setw(6);
       }
       else if (mostart == 2){
       cout &lt;&lt; setw(9);
       }
       else if (mostart == 3){
       cout &lt;&lt; setw(12);
       }
       else if (mostart == 4){
       cout &lt;&lt; setw(15);
       }
       else if (mostart == 5){
       cout &lt;&lt; setw(18);
       }
       else if (mostart == 6){
       cout &lt;&lt; setw(21);
       }
       else if (mostart == 7){
       mostart = 1;
       }
  
       }
  
  
  
  
  
  
  
  int get_numdays(int xmonth, int numdays, int year){ // sets correct amount of days per month. If there is a leap year febuarry will have 29 days.
      if ( xmonth == 1)
      numdays = 31;
      else if ( xmonth == 2){if (isLeapYear(year) == true)
      numdays = 29;
      else
      numdays = 28;}
      else if ( xmonth == 3)
      numdays = 31;
      else if ( xmonth == 4)
      numdays = 30;
      else if ( xmonth == 5)
      numdays = 31;
      else if ( xmonth == 6)
      numdays = 30;
      else if ( xmonth == 7)
      numdays = 31;
      else if ( xmonth == 8)
      numdays = 31;
      else if ( xmonth == 9)
      numdays = 30;
      else if ( xmonth == 10)
      numdays = 31;
      else if ( xmonth == 11)
      numdays = 30;
      else if ( xmonth == 12)
      numdays = 31;
      return numdays;
  }
  
  
  
  
  
  
  void listdays(int numdays, int&amp; mostart){ //This function counts out every single day depending on the month.
      int oneday;
  
      for (oneday=1; oneday &lt;= numdays; ++oneday){
      if(mostart &lt;= 6){
      cout &lt;&lt; oneday &lt;&lt;"  ";
      mostart++;
      }
      else{
       cout &lt;&lt; endl;
       mostart=0;
       start_month(mostart);
  
       cout &lt;&lt; oneday &lt;&lt;"  ";
       mostart++;
      } 
      };
  
  
      cout &lt;&lt; endl;
      }
  
  
  
  
  
  
  
  
  
  
  
  bool isLeapYear(int year){ //determines if the year entered is a leapyear or not if it is a leap year it will return true
                             // if true is returned then it will execute a condition that will make febuary a day longer.
                             // If the condition returns false then febuary will continue to be 28 days.
      if (year % 400 == 0){    
      return true;
      }
  
      if (year % 100 == 0){    
      return false;
      }
      if (year % 4 == 0){
      return true;
      }
      return false;
      }
  </code></pre>