Thread: Months of the year in c

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    1

    Months of the year in c

    i need to write a ‘C’ program that allows the user to enter an integer representing a month and then displays the name of the associated month. e.g., if the user enters the value 1, my program should display January but if the user enters 12, December should be displayed. and also if a irrelevent number is inserted then an error message should appear. also this should all be completed in c

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Months of the year in c

    Originally posted by kingrizzla18
    i need to write a ‘C’ program that allows the user to enter an integer representing a month and then displays the name of the associated month...

    ...also this should all be completed in c
    Great. Go for it.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    7
    Hint: Try some sort of statment where "different cases may be true"

  4. #4
    .
    Join Date
    Nov 2003
    Posts
    307
    They are saying use the switch() statement

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    9

    Thumbs up

    :)
    u can do it - as u have been told using switch statement or else declare a two dimensional character array to do it.

    Code:
    switch(i)
    {
    case 1 : printf("Jan");
                    break;
                   .
                   .
                   .
                   .
    case 12 : priintf("Dec");
                      break;
    default : printf("Enter a valid month ");
                     break;
    }
    
    or else
    
    char mon[12][20]=({"Jan","Feb","Mar",......"Dec"});
    
    
    main()
    { 
    int user_mon;
     /*take the input from the user*/
    
    if(i<1 || i>12)
    printf("Enter a valid number");
    else 
    printf("%s",mon[user_mon]);   
    }

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    45

    reply

    do your homework by yourself
    when u get there, there is isn't any there there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Calendar Problem
    By wordup in forum C Programming
    Replies: 7
    Last Post: 10-29-2002, 03:36 PM
  3. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  4. cant get code to work
    By duffy in forum C Programming
    Replies: 13
    Last Post: 10-20-2002, 05:23 AM
  5. Simplified code
    By soonerfan in forum C Programming
    Replies: 2
    Last Post: 12-05-2001, 03:50 PM