Create monthly calendar with number of days and offset (day of week) as user input I am taking a beginning programming class and have been given the assignment to create a calendar as described in the title.  Per the assignment the user entering offset of 0 will begin the calendar on a monday and 6 will start on sunday.  There are to be 4 spaces per column and the request for input should prompt the user again if the given input isn't a valid option (ie more than 6 days or a month with less than 28 or more than 31 days).

The program works as written, what I am looking for is suggestions/critiques on ways that I might have done it better given what has been taught in the class so far.  It is early in the class, so far it has been limited to pretty much if/else and loops.

#include &lt;iostream&gt;

int getInputDays()
{
  int inputDays = 0;
  bool validInput = false; // used to verify input is valid
  while (validInput == false)
    {
      std::cout &lt;&lt; "Number of Days: ";
      std::cin &gt;&gt; inputDays;
      // will call input valid if between 28 and 31 days
      if (inputDays &gt;= 28 &amp;&amp; inputDays &lt;= 31)
    validInput = true;
    }
  return inputDays;
}

int getInputOffset()
{
  int inputOffset = 0;
  bool validInput = false; // used to verify input is valid
  while (validInput == false)
    {
      std::cout &lt;&lt; "Offset: ";
      std::cin &gt;&gt; inputOffset;
      // will call input valid if between 0 and 6
      if (inputOffset &gt;= 0 &amp;&amp; inputOffset &lt;= 6)
    validInput = true;
    }
  // convert offset from 0 being monday to 0 being sunday
  if (inputOffset == 6)
    inputOffset = 0;
  else
    inputOffset += 1;
  return inputOffset;
}

void displayOffset(int offset)
// used to create offset on the first line of calendar
{
  if (offset == 1)
    std::cout &lt;&lt; "       1";
  else if (offset == 2)
    std::cout &lt;&lt; "           1";
  else if (offset == 3)
    std::cout &lt;&lt; "              1";
  else if (offset == 4)
    std::cout &lt;&lt; "                   1";
  else if (offset == 5)
    std::cout &lt;&lt; "                       1";
  else
    std::cout &lt;&lt; "                           1";
}

void drawCalendar (int days, int offset)
{
  int date = 1;
  int spaces = 0; // used to keep track of location on each line
  std::cout &lt;&lt; "  Su  Mo  Tu  We  Th  Fr  Sa"  &lt;&lt; std::endl;  // calendar header
  while (date &lt;= days)
    {
      if (offset &gt; 0)  // for months starting on any date other than sunday
    {
      displayOffset(offset);
      date = 2;
      spaces = (offset * 4) + 4;
      offset = 0;
    }
      while (spaces &lt; 28) // 28 spaces per line per assignment
    {
      if (date &gt;= 10) // 2 spaces before double digit numbers
        {
          if (date &gt; days)
        break;
          std::cout &lt;&lt; "  " &lt;&lt; date;
        }
      else            // 3 spaces before single digit numbers
        std::cout &lt;&lt; "   " &lt;&lt; date;
      date += 1;
      spaces += 4;
    }
      std::cout &lt;&lt; std::endl;
      spaces = 0; // reset spaces to 0 at the end of each line
    }
}

int main()
{
  // prompt user to input days and offset per assignment
  int days = getInputDays();
  int offset = getInputOffset();
  // use input information to create calendar display
  drawCalendar(days, offset);
}
First Welcome to Code Review, and nice first question for a beginner. You did
a good job with variable names, function names, comments and indentation,
although validInput = true; is incorrectly indented in both functions. The
function drawCalendar() is very inconsistent in the indentation.

Consider the User
You might want to add an error message such as
"Invalid input please enter a number between X and Y" with X being the lower
limit and Y being the upper limit.

DRY Principle
There is a software engineering principle call the Don't Repeat Yourself
principle that may apply to the two input functions. Well written functions
can be used in multiple places in code and decrease the amount of code
necessary to implement a program or library. This code count contain a
function called getInput() that implements most of getInputDays() and
a lot of getInputOffset()

int getInput(string inputPrompt, int lowerBound, int upperBound)
{
  int inputValue = 0;
  bool validInput = false; // used to verify input is valid
  while (validInput == false)
  {
    std::cout &lt;&lt; inputPrompt &lt;&lt; " : ";
    std::cin &gt;&gt; InputValue;
    if (inputValue &gt;= lowerBound &amp;&amp; inputValue &lt;= upperBound)
    {
      validInput = true;
    }
    else
    {
      std::cout &lt;&lt; "Invalid input, please enter a number between"
          &lt;&lt; lowerBound &lt;&lt; " and " &lt;&lt; upperBound &lt;&lt; "\n";
    }
  }
  return InputValue;
}


Reducing the amount of code is a benefit because it makes it easier to
write the code in the first place, modify the code later and debug the
code.

You did well following another software engineering called the Single
Responsibility Principle.
The single responsibility principle states that every module or class should
have responsibility over a single part of the functionality provided by the
software, and that responsibility should be entirely encapsulated by the
class. All its services should be narrowly aligned with that responsibility.

When raw numbers are included in code they can often be confusing. Also if
the same number is used multiple times in the code for the same reason,
such as for array bounds it is easier to understand the code and modify
the code using symbolic constants. Some examples that might apply to
this program

//Symbolic constants should be capitalized, multiple words separated
// by underscore.
constexpr int SHORT_MONTH = 28;
constexpr int LONG_MONTH = 31;
constexpr int SUNDAY = 6;
constexpr int MONDAY = 0;
constexpr int TUESDAY = 1;
constexpr int SPACES_IN_COLUMN = 4;


Switch Statement Versus if then else if
The function displayOffset() could be implemented in the following manner:

void displayOffset(int offset)
// used to create offset on the first line of calendar
{
  switch (offset == 1)
    case TUESDAY :
      std::cout &lt;&lt; "       1";
      break;
    case WEDNESDAY :
      std::cout &lt;&lt; "           1";
      break;
   ...
  }
}


This is somewhat more readable and maintainable that multiple if then else if
statements. It is much easier to add a new case than it is to add a new
else if statement.

Another alternative would be:  

void displayOffset(int offset)
// used to create offset on the first line of calendar
{
  for (int i = 0; i &lt; offset * SPACES_IN_COLUMN; i++)
  {
    std::count &lt;&lt; " ";
  }
}


Complex Functions
It might be easier to understand, debug and modify the drawCalendar()
function if it was broken up into sub-functions following the Single
Responsibility Principle mentioned above.