Thread: Not quite getting it...

  1. #1
    The Hawk Man
    Join Date
    Nov 2005
    Location
    Beaverton, OR USA
    Posts
    13

    Not quite getting it...

    Hi. I've been interested in programming for a long time. I taught myself some basic HTML when I was 11 years old (I'm nearly 21 now) using Joe Burns' tutorial (htmlgoodies.com). Well, I've always wanted to make my own programs (I have some amazing ideas) but I'm not quite sure how to get started. I downloaded a free complier (Dev-C++) and started reading along in the C Tutorial on this site but I'm just not quite getting it. I understand the basic concepts, but I guess my main problem is that I'm not sure how to put it all together for what I want to use it for. I need more resources, I suppose. If you know of great books to read for a beginner in programming (C language is what I'm starting with) or any other tutorials that may be a bit easier to understand, I'd really appreciate it. Thanks.

    -Gavin

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    First off, I think you made a good choice in your compiler selection.

    As far as learning how to put everything together, the first step is learning the language syntax. What different variable types are, how and where to declare them, where semi-colons should and shouldn't go, etc.

    From there, try to start on one of your program ideas. When you get stuck try googling for what you need to do or ask on a forum like this one. Over time you'll learn how to do most things without even knowing you learned them.

    It's difficult (for me at least) to just read a book on something new and learn it without some practical application. Looking for help when you get stuck is probably your best bet.
    If you understand what you're doing, you're not learning anything.

  3. #3
    The Hawk Man
    Join Date
    Nov 2005
    Location
    Beaverton, OR USA
    Posts
    13
    Well, all I know is that I hate not having practical application (I'm the same as you are when it comes to learning). However, I found another tutorial that is much better at explaining at howstuffworks.com. It's kinda cool, actually. It also gives you ideas on how to try to manipulate the code to get better at it. I suppose my main question now is what am I doing wrong? I'm writing my first simple program completely on my own (sort of as a homework thing to myself) to try to better understand what's going on with the code (the functionality of it and such). Anyway...this is what I have so far...

    Code:
    #include <stdio.h>
    
    int main()
    {
        int a;
        char b;
        {
              printf("Please enter your age: ");
              getchar();
              scanf("%d", &a);
              printf("Please enter the first letter of your first name: ");
              getchar();
              scanf("%c", &b);
              printf("Thank you, %c. Have a great day. You're %d years old!", b, a);
              getchar();
              scanf("%c, %d", &b, &a); 
    }
              return 0;
    }
    Anyway, my program is meant to basically allow user input and then repeats what the put in with the last printf statement. The problem is apparant when I run the program. It goes along fine until the end when it says "Thank you, G. Have a great day. You're 0 years old!". Even though I enter in 20 as the age, it still says 0 and I can't seem to figure out why. Any help would be much appreciated. Thanks.

    -Gavin

    PS Thanks for the previous advice/information.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by GavinHawk
    Code:
    #include <stdio.h>
    
    int main()
    {
        int a;
        char b;
        {
              printf("Please enter your age: ");
              getchar();
              scanf("%d", &a);
              printf("Please enter the first letter of your first name: ");
              getchar();
              scanf("%c", &b);
              printf("Thank you, %c. Have a great day. You're %d years old!", b, a);
              getchar();
              scanf("%c, %d", &b, &a); 
    }
              return 0;
    }
    See those getchar() calls? They're objective in your program is to take away the '\n' character after each input. Switch the scanf() and getchar() around.
    Sent from my iPadŽ

  5. #5
    The Hawk Man
    Join Date
    Nov 2005
    Location
    Beaverton, OR USA
    Posts
    13
    Quote Originally Posted by SlyMaelstrom
    See those getchar() calls? They're objective in your program is to take away the '\n' character after each input. Switch the scanf() and getchar() around.
    Holy CRAP! Thank you SO much! I feel like a programmer already! Thanks again! YAY! *does the happy dance*

    -Gavin

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    38
    Worked fine for me...

  7. #7
    The Hawk Man
    Join Date
    Nov 2005
    Location
    Beaverton, OR USA
    Posts
    13
    Quote Originally Posted by Barnzey
    Worked fine for me...
    *shrugs* Yeah, for some reason it printed "Thank you, G! Have a great day. You're 0 years old!"....dunno why it worked for you and not me. But now it's fixed!

  8. #8
    Registered User
    Join Date
    Nov 2005
    Posts
    95
    Hi GavinHawk

    Could u please post a link for c in "howstuffworks.com" ?

    Thanks in advance.

  9. #9

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I think I heard somewhere that that isn't a good resource.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    The Hawk Man
    Join Date
    Nov 2005
    Location
    Beaverton, OR USA
    Posts
    13
    Quote Originally Posted by dwks
    I think I heard somewhere that that isn't a good resource.

    It's working really well for me.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by GavinHawk
    Code:
    #include <stdio.h>
    
    int main()
    {
        int a;
        char b;
        { /* <-- This is pointless. */
              printf("Please enter your age: ");
              /* <-- Should flush output here. */
              getchar(); /* <-- Shouldn't be here. */
              scanf("%d", &a);
              /* <-- getchar should be here, if you're going to use it */
              printf("Please enter the first letter of your first name: ");
              /* <-- Should flush output here. */
              getchar(); /* <-- Not here. */
              scanf("%c", &b);
              /* <-- getchar should be here, if you're going to use it */
              printf("Thank you, %c. Have a great day. You're %d years old!", b, a);
              /* <-- Should flush output here. */
              getchar();
              scanf("%c, %d", &b, &a); /* <-- This is pointless. */
        } /* <-- This is pointless. */
              return 0;
    }
    As you can see, there are a few minor issues with the code.


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

Popular pages Recent additions subscribe to a feed