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; OK. Your case label is wrong. Case only accepts either a number of a constant. So you can say case ...

  1. #31
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    OK. Your case label is wrong. Case only accepts either a number of a constant. So you can say case February, because February = 2, which is how you defined your enum.
    Now, think about this: when you're inside your February case statement. You're printing that Feb has 28 days at the moment. How about putting your leap-year check within the case statement, and then print out either 28 or 29 depending?

    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

  2. #32
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    thx for the reply
    but how do i place the leap-year check within the case statement.
    do i have to define leap yr from the beginning?

  3. #33
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    Inside your February case, use an if to determine if it's a leap year or not and print appropriate information. Shouldn't be difficult.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #34
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    thx elysia for u help again
    this is for i got so far... where should i put the if statement for leap yr? cause the below codes dont work when i compile it
    Code:
    switch(month)
    {
       case January:
         printf("January has 31 days\n");
    break;
    
       if (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&&
            (year%4==0)))&& case  February:
    
         printf("February has 29 days\n");
    
       else
    
        printf("February has 28 days\n");
    
    }
    return 0;
    }

  5. #35
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    Well, of course it won't.
    If you think logically... make an internal flowchart.
    Where does the leap year code need to be put?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #36
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    sorry i have only learnt c for a couple of days
    whatz an internal flowchart?

  7. #37
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    It means that you design or write down how want you want to perform flows.
    So, for example, in your example, a simple flowchart might be:

    Read input from user
    ...
    Close program

    By writing down each step, you can easily know where to place code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #38
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    C programs are a sequence of instructions to do things. A flowchart is a diagramatic way to describe how a program works.

    But you don't need to have a flowchart - you can use many other ways to describe the code. What is important is that you understand that the compiler has very strict rules about what goes where, and how the code can and can't be organized, and the sequence of your code is important. If you want to bake a cake, you have to do things in order: turn on the oven, mix the ingredients, pour the mix in a cakeform, then put it in the oven, wait a specified amount of time, then take the cake out and turn off the oven. If you put the raw ingredients in the oven, then mix them afterwards, it won't be a cake - it may still turn out to be sort of edible, but chances are that it won't be very nice.

    Same applies to programs - your program is a RECIPE for doing some particular calculations or work.

    --
    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.

  9. #39
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    ah k thx i sort of think logically for a while but my method still don't work (sorry im dumb)
    Code:
    switch(month)
    {
       case January:
         printf("January has 31 days\n");
    break;
    
        case  February:
          printf("February has 28 days\n");
     
        else if (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&&
            (year%4==0)))
    
        printf("February has 28 days\n");
     
    }
    return 0;
    }

  10. #40
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    You have "else if" without if.
    How can you "do something else" without "something" first?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #41
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    any tips at all about where i need to put or define the leap year code in the program?
    because im really lost

  12. #42
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You're on the right track, but you're still making a hash of it.

    You need to start with an if, not an else. And you probably want that FIRST, then print afterwards - like cake-baking, you're currently putting the ingredients in first (printing 28 days), then mixing (checking if it's a leapyear).

    --
    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.

  13. #43
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Code:
    enum months
    {
    	January = 1, 
    	February, 
    	March, 
    	April, 
    	May, 
    	June, 
    	July,
    	August, 
    	September, 
    	October, 
    	November, 
    	December
    };
    
    int main()
    {
    	int year;
    	enum months month;
    	printf("Enter year and month:");
    	scanf("%d %d", &year, &month);
    	
    	switch(month)
    	{
    	case January:
    		printf("January has 31 days\n");
    		break;
    	case February:
    		if (((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");
    		}
    		break;
    	case March:
    		printf("March has 31 days\n");
    		break;
    	}
    	
    	return 0;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  14. #44
    Registered User
    Join Date
    Mar 2008
    Posts
    45
    thx mats
    but i thought i need to get the program to check whether the input before for the year is leap or not
    then decide whether feb is 28 or 29 days
    Code:
    //Create by z3252440
    #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("&#37;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;
    
        if (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&&
         (year%4==0)))
    
        case February:
    
        printf("February has 28 days\n");
    
        else
    
        printf("February has 29 days\n");
    break;
    }
    
    return 0;
    }
    As can seen above shouldnt the program check the year then decide which statement to print?
    cause this is where i am getting really confuse

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

Page 3 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, 09:19 PM
  2. The ultimate noob lol...plz help
    By thatpkrguy in forum C++ Programming
    Replies: 14
    Last Post: 11-10-2005, 05:53 PM
  3. plz help here, noob actually .D
    By BjoRn3n in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2005, 02:04 PM
  4. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM
  5. noob: compiling error... plz help!
    By chosii in forum C Programming
    Replies: 2
    Last Post: 05-10-2002, 05:53 AM

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