Thread: please i need help

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    62

    please i need help

    hi guys i really need help on this programming, my program is not compliling and i need help. i also need to i dont understand what my program is doing in the loop.
    Code:
    #include<math.h>
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    float x,y;
    int i,j,k[5];
    char letter, course[] = "numerical methods";
    
            printf("%c %s\n", course[6], course);     
            printf("%c %s\n", course[6], &course[]); 
    
            for(i=0; i<5; i++)  {k[i]=3+i};
            j =*(k+2);
            printf("%d %d\n", k[2],j);
    
            getch();
    }
    Last edited by joker_tony; 08-01-2009 at 08:41 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    It is not possible for a program to both "not compile" and "give output". Choose whichever one is true. If it does not compile, read the error messages, which will tell you exactly why it doesn't compile.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    i got it form a tutorial book

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Then you should fix the errors introduced when you typo'ed the program from the book (unless the point of the exercise was for you to find the errors in the first place). And the compile messages tell you why it doesn't compile.

    And how hard is "k[i]=3+i" to understand? (Apart from that being one of your syntax errors, of course. But the intent of the line is obvious.)

  5. #5
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Here is why it doesn't compile -

    printf("%c %s\n", course[6], &course[]);
    Empty subscript is invalid, you can simply do course, or &course[0]

    for(i=0; i<5; i++) {k[i]=3+i};
    Semicolon comes before the curly brace.
    i dont understand why my the output is 3, 12
    How are you getting output if your program didn't compile ?

    EDIT : ah, I see. Well step through it and see why you would get that output.
    Spidey out!

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    my program still doesnt compile

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by joker_tony View Post
    my program still doesnt compile
    Just reading about how to fix things won't help: you will have to actually make the appropriate changes in your program.

  8. #8
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by tabstop View Post
    Just reading about how to fix things won't help: you will have to actually make the appropriate changes in your program.
    LOL!
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    i try

  10. #10
    Registered User
    Join Date
    Jul 2009
    Posts
    24
    i've been using C for less than 3 days, i see 4 errors. this code really doesn't need much to get it working.


    what does the book say you are supposed to be getting for an output?
    Last edited by SlyVixsky; 08-01-2009 at 10:32 PM.

  11. #11
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    would you give me a favorutie and tell me what is wrong with it please

  12. #12
    Registered User
    Join Date
    Jul 2009
    Posts
    24
    Quote Originally Posted by joker_tony View Post
    would you give me a favorutie and tell me what is wrong with it please
    If you tell me what the output is supposed to be, ill point you in the general direction, as the rest of the replies have, but i'm not going to post a full program. Ill need the output to be sure I've done it right myself before i can offer accurate help.

  13. #13
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    output is
    c numerical method
    6 ,6
    Last edited by joker_tony; 08-01-2009 at 11:04 PM.

  14. #14
    Registered User
    Join Date
    Jul 2009
    Posts
    24
    ok, what i want you to do is erase it and re-type the program from the book, and double check yourself, then if it wont compile, repost it. i wanna be sure i have the right program to start with

  15. #15
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by joker_tony View Post
    output is
    c numerical method
    6 ,6
    The code you posted has three output lines, and here you only have two lines of output. Another mistyping, I guess? And if you had typed the second part correctly then I would expect 5 and 5 instead.

Popular pages Recent additions subscribe to a feed