Link to home
Start Free TrialLog in
Avatar of jribble
jribble

asked on

Get text month given integer month

I know I can write a simple function to do this, but can show me an existing library function to return the text month (i.e., Jun or June) given the integer representation (1-12).

Thanks,

Joe
ASKER CERTIFIED SOLUTION
Avatar of mrwad99
mrwad99
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of List244
List244

#include <iostream>

using namespace std;

const char* Month[] = {"Months:","January","Febuary","March","April",
      "May","June","July","August","September","October","November",
      "December"};
int main ()
{
      cout << "Please enter a month (1-12):";
      int GMonth;
      cin >> GMonth;
      cout << "The month you entered was, " << Month[GMonth] << endl;
      return 0;
}

I know this isn't what you want, but I personally would just use an array like this.  That way your program
relies on a lot less for doing this.  For example, MrWad's example requires Time.h and Tchar.h and still
is based on 0-11 not 1-12.  Is there a reason you want to use built-in libraries?