User-defined function for magazine subscription program
<p>I'm working on this programming assignment that has me creating a program that handles renewal and cancellation notices for magazine subscriptions, based on the month and year the user inputs. Part of the program focuses on reusing old code (which is what the extended switch is from). The function that I made with the reused code instead of displaying the actual month, equates the month with a number (1-12, correlating to each month). My issue is that I'm trying to make a separate function that takes the number and converts it the actual name of the month. This is what I have so far:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;iomanip&gt;
#include &lt;cstdlib&gt;

using namespace std;

void getMonth(char first, char second, char third, int&amp; monthNumber);
void getYear(int&amp; yearNumber);
void convertMonthNumber(int monthNumber, string&amp; month);

int main()
{
    char first, second, third;
    int monthNumber = 0;
    int yearNumber = 0;
    string month;    

    cout &lt;&lt; "Subscription Evaluation Program";
    cout &lt;&lt; endl &lt;&lt; endl;
    getMonth(first, second, third, monthNumber);
    getYear(yearNumber);
    convertMonthNumber(monthNumber, month);

    cout &lt;&lt; "The current date is " &lt;&lt; month &lt;&lt; " " &lt;&lt; yearNumber; //Test to see if  convertMonthNumber works

    system("PAUSE");
}

void getMonth(char first, char second, char third, int&amp; monthNumber)
{  
    cout &lt;&lt; "Enter first letter of the current month: ";
    cin &gt;&gt; first;

switch(first)
{
    case 'F':
    case 'f':
        {
             int montNumber = 2;
        }
        break;
    case 'S':
    case 's':
         {
             int monthNumber = 9;
         }
        break;
    case 'O':
    case 'o':
        {
             int monthNumber = 10;
        }
        break;
    case 'N':
    case 'n':
        {
             int monthNumber = 11;
        }     
        break;
    case 'D':
    case 'd':
        {
             int monthNumber = 12;
        }
        break;
    case 'A':
    case 'a':
    {
        cout &lt;&lt; "Enter second character of month: ";
        cin &gt;&gt; second;

        switch(second)
        {
            case 'P':
            case 'p':
                {
                     int monthNumber = 4;
                }
                break;
            case 'U':
            case 'u':
                {
                     int monthNumber = 8;
                }
                break;
            default:
                cout &lt;&lt; "Unknown Month";
                cout &lt;&lt; endl;
          }
    }
break;
case 'J':
case 'j':
{
    cout &lt;&lt; "Enter second character of month : ";
    cin &gt;&gt; second;
    switch(second)
    {
        case 'A':
        case 'a':
            {
                 int monthNumber = 1;
            }
            break;
        case 'U':
        case 'u':
            cout&lt;&lt;"\nEnter third character: ";
            cin &gt;&gt; third;
            switch(third)
            {
                case 'L':
                case 'l':
                    {
                         int monthNumber = 7;
                    }    
                    break;
                case 'N':
                case 'n':
                    {
                         int monthNumber = 6;
                    }
                    break;
                default:
                    cout &lt;&lt; "\nUnknown Month";
            }
            break;
        default:
            cout &lt;&lt; "\nUnknown Month";
            cout &lt;&lt; endl;
    }
    break;
    case 'M':
    case 'm':
        cout &lt;&lt; "Enter second and third characters: ";
        cin &gt;&gt; second;
        cin &gt;&gt; third;
        switch(second)
        {
            case 'A':
            case 'a':
                {
                    switch(third)
                    {
                        case 'R':
                        case 'r':
                            {
                                 int monthNumber = 3;
                            }     
                            break;
                        case 'Y':
                        case 'y':
                            {
                                 int monthNumber = 5;
                            }    
                            break;
                        default:
                            cout &lt;&lt; endl &lt;&lt; "Unknown Month";
                            cout &lt;&lt; endl;
                    }
                }
                break;
            default:
                cout &lt;&lt; endl &lt;&lt; "Unknown Month";
                cout &lt;&lt; endl;
        }
    break;
    default:
        cout &lt;&lt; endl &lt;&lt; "Unknown Month";
        cout &lt;&lt; endl;
        return;
    }
}
</code></pre>

<p>}</p>

<pre><code>void getYear(int&amp; yearNumber)
{
    const int LOW_YEAR_LIMIT = 2012;
    const int HIGH_YEAR_LIMIT = 2017;

    do{
    cout &lt;&lt; "Enter current year (4 digits): ";
    cin &gt;&gt; yearNumber;
    if (yearNumber &lt; LOW_YEAR_LIMIT || yearNumber &gt;= HIGH_YEAR_LIMIT){
        cout &lt;&lt; endl;
        cout &lt;&lt; "Invalid year. Please enter again.";
        cout &lt;&lt; endl &lt;&lt; endl;
        }
    }while (yearNumber &lt; LOW_YEAR_LIMIT || yearNumber &gt;= HIGH_YEAR_LIMIT);
    return;
}

void convertMonthNumber(int monthNumber, string&amp; month)
{    
    if (monthNumber = 1)
        string month = January;
    else if (monthNumber = 2)
         string month = February;
    else if (monthNumber = 3)
         string month = March;
    else if (monthNumber = 4)
         string month = April;
    else if (monthNumber = 5)
         string month = May;
    else if (monthNumber = 6)
         string month = June;
    else if (monthNumber = 7)
         string month = July;
    else if (monthNumber = 8)
         string month = August;
    else if (monthNumber = 9)
         string month = September;
    else if (monthNumber = 10)
         string month = October;
    else if (monthNumber = 11)
         string month = November;
    else if (monthNumber = 12)
         string month = December;  
    return;
}
</code></pre>

<p>So I took some of your suggestions and did this; it's not returning the month back.</p>

<pre><code>void convertMonthNumber(int monthNumber, string&amp; month)
{  
    const string JANUARY = "January";
    const string FEBRUARY = "February";
    const string MARCH = "March";
    const string APRIL = "April";
    const string MAY = "May";
    const string JUNE = "June";
    const string JULY = "July";
    const string AUGUST = "August";
    const string SEPTEMBER = "September";
    const string OCTOBER = "October";
    const string NOVEMBER = "November";
    const string DECEMBER = "December";

    if (monthNumber == 1)
         month = JANUARY;
    else if (monthNumber == 2)
         month = FEBRUARY;
    else if (monthNumber == 3)
         month = MARCH;
    else if (monthNumber == 4)
         month = APRIL;
    else if (monthNumber == 5)
       month = MAY;
    else if (monthNumber == 6)
         month = JUNE;
    else if (monthNumber == 7)
         month = JULY;
    else if (monthNumber == 8)
         month = AUGUST;
    else if (monthNumber == 9)
         month = SEPTEMBER;
    else if (monthNumber == 10)
         month = OCTOBER;
    else if (monthNumber == 11)
         month = NOVEMBER;
    else if (monthNumber == 12)
         string month = DECEMBER;  
    return;
}
</code></pre>
