a program to create months in a year newbie question

This is a discussion on a program to create months in a year newbie question within the C Programming forums, part of the General Programming Boards category; I am supposed to do the following assignment as stated below can anyone tell me if I am going on ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    76

    a program to create months in a year newbie question

    I am supposed to do the following assignment as stated below can anyone tell me if I am going on the right direction?



    Write and compile a C Program to declare an enumerated data type to hold values of 12 months in a year. Declare 12 variables of this data type initialized with 12 different months.
    Code:
    enum   Months{
    
                January,
    
                February,
    
                March,
    
                April,
                
                May,
                
                June,
                
                July,
                
                August,
                
                September,
                
                October,
                
                November,
                
                December
                
                
    
    };
    
    #include <conio.h>
    #include <stdio.h>
    main(){
          
          typedef enum months month;
          
          month month1 = january;
         
           
          
          getche(); 
           }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Close... you must remember that January is different from january since C is case-sensitive.

    Code:
    #include <conio.h>
    #include <stdio.h>
    
    enum Months{ January, February, March, April, May, June,
                 July, August, September, October, November, December };
    
    
    int main()
    {
        typedef enum months month;
    
        month month1 = January;  // Case sensitive
    
        // Declare other 11 variables here...
    
        getche(); 
    
        return 0;
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    76
    oops! I missed that J in january.and I also missed M in month it's working goodd now thanks.
    Code:
    enum   Months{
    
    January, February, March, April, May, June, July,
                
    August, September, October, November, December
    };
    
    #include <conio.h>
    #include <stdio.h>
    main(){
          
    typedef enum Months month;
    month month1 = January;
     month month2 = February;
     month month3 = March;
     month month4 = April;
     month month5 = May;
     month month6 = June;
     month month7 = July;
     month month8 = August;
     month month9 = September;
     month month10 = October;
     month month11 = November;
     month month12 = December;
      
    
          
          getche(); 
           }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. Help with leap year program.
    By IxTanGxI in forum C Programming
    Replies: 8
    Last Post: 02-20-2006, 07:49 PM
  3. newbie question about linked list
    By gemini_shooter in forum C Programming
    Replies: 10
    Last Post: 04-13-2005, 10:50 PM
  4. Leap year program prints wrong output
    By Guti14 in forum C Programming
    Replies: 8
    Last Post: 08-24-2004, 11:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21