Entry Level Help.

This is a discussion on Entry Level Help. within the C Programming forums, part of the General Programming Boards category; Ice Dane, I am a junior Electrical engineering student and this is the only programming course I have to take. ...

  1. #16
    Registered User
    Join Date
    Feb 2008
    Posts
    32
    Ice Dane, I am a junior Electrical engineering student and this is the only programming course I have to take. We are on "loops" in the book and that is what is supposed to be used for the assignment. No arrays, just statements and loops. Let me remind you all this is an INTRO level course. Some of the stuff you guys have said isn't even in my book or is on the last few chapters. I will have the solution for program tomorrow and post it.

    I think this board is a little to far advanced for me. You guys really know your stuff. Way out of my league. =)
    Last edited by alex1067; 03-11-2008 at 03:15 AM.

  2. #17
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > I believe enumerated constants start at 0 by default.
    They do, and I pointed out your error.

    Code:
    int iLike;
    
    printf("What fruit do you like?\n");
    printf("1. Apple\n");
    printf("2. Orange\n");
    printf("3. Banana!\n");
    printf("4. Lemon?\n");
    scanf("%d", &iLike);
    iLike++;   /* the enum constants start from 0 in this example */
    If the user enters, 1 for apple. They then like 1 + 1 = 2 (Banana), Rather than 1 - 1 = 0 (Apple).

    In short you increased iLike when you should have decreased it. That means you go out-of-bounds when you try to access a "Lemon" for example. It's name would then be... according to you fruitname[5] (out-of-bounds) -- No, it's fruitname[3]. Run it through a debugger and see for yourself.

    > As for the test, it was purposefully written such that it demonstrates the readability of enum constants versus "magic" numbers.
    No excuse for errors
    Last edited by zacs7; 03-11-2008 at 03:40 AM.

  3. #18
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355

    Talking

    Quote Originally Posted by zacs7 View Post
    > I believe enumerated constants start at 0 by default.
    They do, and I pointed out your error.
    True, i meant --
    No excuse for errors
    True. Compilers make errors, humans with a vast dislike for sleep almost never.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  4. #19
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,641
    Quote Originally Posted by alex1067 View Post
    We are on "loops" in the book and that is what is supposed to be used for the assignment. No arrays, just statements and loops.
    Except there's no loop at all in your code

  5. #20
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    Quote Originally Posted by alex1067 View Post
    Ice Dane, I am a junior Electrical engineering student and this is the only programming course I have to take. We are on "loops" in the book and that is what is supposed to be used for the assignment. No arrays, just statements and loops. Let me remind you all this is an INTRO level course. Some of the stuff you guys have said isn't even in my book or is on the last few chapters. I will have the solution for program tomorrow and post it.

    I think this board is a little to far advanced for me. You guys really know your stuff. Way out of my league. =)

    Well if your an Electrical Engineer, to be honest there's no escaping programming. In fact it's kind of ridiculous that EE's have to take only one programming course when almost all embedded programmers are EE's/CE's. So learn from these people, because when it comes time to programming a microcontroller which you can either code in assembly or C and most industries would choose C because of it's maintainability and portability, you'll wish you'd paid attention to these peoples suggestions.

  6. #21
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    I'm a EE that writes C for a living. I wouldn't want to escape programming, even if I could. It's a lot better than E-mag.

  7. #22
    Registered User
    Join Date
    Feb 2008
    Posts
    32
    Electromagnetics has been my favorite course

    How similar is C programming to MATlab?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble writing to file using fwrite()
    By yougene in forum C Programming
    Replies: 4
    Last Post: 12-30-2008, 04:13 PM
  2. Diablo's random level generation
    By glo in forum Game Programming
    Replies: 7
    Last Post: 07-19-2008, 03:04 AM
  3. Listing binary tree numbers by level
    By Nazgulled in forum C Programming
    Replies: 5
    Last Post: 06-16-2008, 10:36 AM
  4. Binary Search Tree
    By penance in forum C Programming
    Replies: 4
    Last Post: 08-05-2005, 05:35 PM
  5. Salary for entry level C position- How much can you make?
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 08-10-2002, 11:54 PM

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