Please Help A Noob Here (plz Im Begging You)

This is a discussion on Please Help A Noob Here (plz Im Begging You) within the C Programming forums, part of the General Programming Boards category; Lol, yes March has 31 days. I should have used the knuckle method to find that out....

  1. #16
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Lol, yes March has 31 days. I should have used the knuckle method to find that out.

  2. #17
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    you guys are all blooldy legends first of all and thx for the enum method slingerland3g
    but can someone explain to me how the enumeriatsaion method works
    and can someone give me some tips on how to convert years into words>??? cause i have absolute no idea

  3. #18
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    Enumeration is like defining an integer type, but only allowing the values 0, 1, 2. If the user tries to assign anything other than a 0, 1, 2, you get an error.

    Code:
    typedef enum
    {
    	ENUMERATION_1,
    	ENUMERATION_2,
    	ENUMERATION_3
    } enumeration;
    
    enumeration a;
    enumeration b;
    It's useful for assigning descriptive names to certain values that a variable can take.

  4. #19
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    so since i have to create a calender from january to decemeber
    enumeration wont work eh cause it only works for intergers for 0, 1, 2 but not 3 onwards...
    so what other methods can i use if i did to include integers from 0 to 12

  5. #20
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    cause it only works for intergers for 0, 1, 2 but not 3 onwards
    Why do you say so? enum could include any integer you want

    integers from 0 to 12
    Why do you need 13 months?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #21
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    for marking an error code

  7. #22
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    hi guys im just wondering how to make an else if comment this is what i got so far....
    if (month == January)
    printf("Janurary has 31 days\n");
    else if ((month == February)&& (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&& (year%4==0))))
    { printf("February has 29 days\n");
    }
    else
    { printf ("February has 28 days\n");
    }


    However it does not work

  8. #23
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    use switch

    Code:
    enum months {Jan,Feb,Mar,...} month;
    switch(month)
    {
       case Jan: ...
          break;
       case Feb:
    ...
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #24
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    u mind explaining briefly about how switch works plz?

  10. #25
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  11. #26
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by bobbie18 View Post
    hi guys im just wondering how to make an else if comment this is what i got so far....
    if (month == January)
    printf("Janurary has 31 days\n");
    else if ((month == February)&& (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&& (year%4==0))))
    { printf("February has 29 days\n");
    }
    else
    { printf ("February has 28 days\n");
    }
    However it does not work
    Post code within code tags! and indent properly.
    Code:
    if (month == January) {
        printf("Janurary has 31 days\n");
    } else if ((month == February) && 
               ( ((year%4 == 0 ) && (year%100 != 0)) || 
                 ((year%400 == 0) && (year%100 == 0) && (year%4 == 0))
               )
              ) { 
        printf("February has 29 days\n");
    } else { 
        printf ("February has 28 days\n");
    }
    Also use braces with all if/else statements or at least don't mix an if statement without braces with an else statement with braces!
    I've also re-aligned your if statement a bit, so you can see whether you're doing what you're intending to do.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  12. #27
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    hi i sort of fixed it but don't know what i did wrong when i want the printf statement to be Feb has 29 days when it's a leap year... Code as follow: THX A LOT GUYS

    switch(month)
    {
    case January:
    printf("January has 31 days\n");
    break;
    case February:
    printf("February has 28 days\n");
    break;
    case (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&&
    (year%4==0))) February:
    printf("February has 29 days\n");
    }

  13. #28
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need to put the condition to examine if it's a leap-year inside the case for February:
    Code:
    if (leap_year) ... 29
    else ... 28
    The case-label, e.g. Februry, must be constant, it can not be "an equation" - it MUST be something that the compiler can figure out at compile time into a simple number.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #29
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    This might work by repetitive instruction:
    use code tags.

    << !! Posting Code? Read this First !! >>

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  15. #30
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    Code:
    #include <stdio.h>
    
    int main()
    {
            int year, month;
            enum months{January = 1, February, March, April, May, June, July,
            August, September, October, November, December};
    
            printf("Enter year and month:");
            scanf("%d %d", &year, &month);
            if (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&&
            (year%4==0)))
            {
                    printf("has three hundred and sixty six (366) days\n");
            }
            else
            {
                    printf("has three hundred and sixty five (365) days\n");
            }
    
    switch(month)
    {
       case January:
         printf("January has 31 days\n");
    break;
       case February:
         printf("February has 28 days\n");
    break;
       case (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&&
            (year%4==0))) February:
        printf("February has 29 days\n");
    }
    
    return 0;
    }

Page 2 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 10:19 PM
  2. The ultimate noob lol...plz help
    By thatpkrguy in forum C++ Programming
    Replies: 14
    Last Post: 11-10-2005, 06:53 PM
  3. plz help here, noob actually .D
    By BjoRn3n in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2005, 03:04 PM
  4. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 09:44 AM
  5. noob: compiling error... plz help!
    By chosii in forum C Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 AM

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