English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

currently programming in c++ for a uni module, need to convert the integer 01 into a word, i.e. 01 = january, 02 = feb...etc..

any help welcome :D

2006-11-14 09:58:36 · 2 answers · asked by jimmyhigginz 1 in Computers & Internet Programming & Design

2 answers

char *Months[] = { "January", "February", "March", ... "December"};

char *GetMonth( int Index )
{
return( Months[Index - 1] ); // Note -1 because first month is 1 not 0
}

2006-11-14 10:39:23 · answer #1 · answered by Martin 5 · 3 0

Martins answer is fine but an other way would be to use nested if statements or even a switch, eg:

in pseudo code:

int month;

if(month==1)return jan;
if(month==2)return feb;

or

String month;
int monthint;

if(monthint==1)month = "jan";

something like that...

2006-11-15 00:16:56 · answer #2 · answered by karljj1 4 · 0 0

fedest.com, questions and answers