Monday, July 13, 2009

How can i convert 01 an integer into January etc in c++ coding?

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

How can i convert 01 an integer into January etc in c++ coding?
char *Months[] = { "January", "February", "March", ... "December"};





char *GetMonth( int Index )


{


return( Months[Index - 1] ); // Note -1 because first month is 1 not 0


}
Reply: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...


No comments:

Post a Comment