Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,495 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,343 people online right now. Registration is fast and FREE... Join Now!




C++ Program problems with month conversion

 
Reply to this topicStart new topic

C++ Program problems with month conversion

dt52fast
21 Mar, 2007 - 12:27 PM
Post #1

New D.I.C Head
*

Joined: 21 Mar, 2007
Posts: 11


My Contributions
Hello all, I am writting a program that will read in a date and convert the form then print it back out. I have day and year figured out but month is boggling me. I want to read in a number and print the letter month

ie if 2 is entered I need to print February

I have constants set for all months as const int February = 2;

But I do not know how to select the correct constant and print the characters.

Can someone help with an example?

Thanks

Kerry
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: C++ Program Problems With Month Conversion
21 Mar, 2007 - 03:47 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,867



Thanked: 53 times
Dream Kudos: 550
My Contributions
well you could:

CODE
If (month == February) {cout << "Feb"; }


or you could
CODE

switch (month)
{
    case January:
      cout << "Jan";
      break;
    case February:
      cout << "Feb";
      break;
...
}


Or you could:
CODE

    string Months[] = {"Jan", "Feb", "Mar", ...};
    cout << Months[month - 1];
I am sure there are a few more methods but those I think are the more common types.

This post has been edited by NickDMax: 21 Mar, 2007 - 03:48 PM
User is offlineProfile CardPM
+Quote Post

dt52fast
RE: C++ Program Problems With Month Conversion
23 Mar, 2007 - 07:03 PM
Post #3

New D.I.C Head
*

Joined: 21 Mar, 2007
Posts: 11


My Contributions
QUOTE(dt52fast @ 21 Mar, 2007 - 01:27 PM) *

Hello all, I am writting a program that will read in a date and convert the form then print it back out. I have day and year figured out but month is boggling me. I want to read in a number and print the letter month

ie if 2 is entered I need to print February

I have constants set for all months as const int February = 2;

But I do not know how to select the correct constant and print the characters.

Can someone help with an example?

Thanks

Kerry


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 06:08PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month