Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,411 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,463 people online right now. Registration is fast and FREE... Join Now!




Displays the month corresponding to a number entered by the user

 
Reply to this topicStart new topic

Displays the month corresponding to a number entered by the user

liko
15 Oct, 2008 - 02:04 AM
Post #1

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 32

I just need to make a program with the numbers making it just put the number and it will be the month. Example 1 would be January. Also i need to put the condition of error if its more than 12 and less than 0. I don't know what to start with help appreciated biggrin.gif

CODE

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{    
    //declare variable
    int month = 0;
    double

    //enter input
    cout << "Enter the month number: ";
    cin >> month;

    //display output
    
    return 0;
}   //end of main function


User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Displays The Month Corresponding To A Number Entered By The User
15 Oct, 2008 - 02:07 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,462



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
The way I would do this is to make an array being the character representations of the months.

CODE

int i=0;
Month_Alph[12][32];

for(i=0;i<12;i++) {
  printf("%s\n",Month_Alph[i]);
}


User is online!Profile CardPM
+Quote Post

schnalf
RE: Displays The Month Corresponding To A Number Entered By The User
15 Oct, 2008 - 02:12 AM
Post #3

D.I.C Head
**

Joined: 9 Feb, 2008
Posts: 124



Thanked: 2 times
My Contributions
the switch statement would be the right for you:

cpp

switch(month) //for variable month
{
case 1: //if month == 1 do
cout << "January" << endl;
break; //exit the switch statement

case 2: //if month == 2 do
cout << "February" << endl;
break; //exit the switch statement

case 3: //if month == 3 do
cout << "March" << endl;
break; //exit the switch statement

....

default: //for all other cases do
cout << "wrong input" << endl;
}

User is offlineProfile CardPM
+Quote Post

liko
RE: Displays The Month Corresponding To A Number Entered By The User
15 Oct, 2008 - 10:23 AM
Post #4

New D.I.C Head
*

Joined: 19 Apr, 2008
Posts: 32

ahh thank you so much made it seem easier now biggrin.gif. I appreciate the help smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 12:22PM

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