C++ char array of strings

Description

C++ char array of strings

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

const char * const pszMonths[] = {"void","January","February","March","April","May","June","July","August","September","October","November","December"};

const char* int2Month(int nMonth){
    if (nMonth < 1 || nMonth > 12){
        return "invalid";
    }//from w w  w  . j a  va  2 s .  c  om
    return pszMonths[nMonth];
}

int main(int nNumberofArgs, char* pszArgs[]){
    cout << "Enter the number of the month to display\n" << "(Enter a negative number to quit)" << endl;
    for(;;){
        cout << "Month?";
        int nMonth;
        cin >> nMonth;
        if (nMonth < 0)
        {
            break;
        }
        cout << "That would be "<<int2Month(nMonth)<<endl;
    }
    return 0;
}



PreviousNext

Related