C programming help please!

This is a discussion on C programming help please! within the C Programming forums, part of the General Programming Boards category; I just now got thrown into visual studio and told to make a basic(simple) program even though I don't know ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    4

    C programming help please!

    I just now got thrown into visual studio and told to make a basic(simple) program even though I don't know anything about the language or syntax, no help was given relating to the assignment, and he answers my questions with riddles. The professor won't tell me if we're correct until after the assignment is turned in. So I'm asking for the mercy of someone that will give me a quick run-through of how to do this program.

    This is the exact assignment from the professor:

    Problem to be solved:

    Input from the user five numbers. Determine, and print out, the smallest number entered and the second smallest number entered.

    Do NOT use loops, which we have not yet discussed.

    Example run (bold type is what is entered by the user):



    Enter number 1: 15

    Enter number 2: 27

    Enter number 3: 36

    Enter number 4: 12

    Enter number 5: 9



    The smallest number is: 9

    The second smallest number is: 12


    Do NOT use loops, which we have not yet discussed.

    -----

    If anyone could give me a quick run-down, I would be eternally greatful!
    Thanks in advance!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    Quote Originally Posted by brown287 View Post
    I just now got thrown into visual studio and told to make a basic(simple) program even though I don't know anything about the language or syntax, no help was given relating to the assignment, and he answers my questions with riddles. The professor won't tell me if we're correct until after the assignment is turned in. So I'm asking for the mercy of someone that will give me a quick run-through of how to do this program.

    This is the exact assignment from the professor:

    Problem to be solved:

    Input from the user five numbers. Determine, and print out, the smallest number entered and the second smallest number entered.

    Do NOT use loops, which we have not yet discussed.

    Example run (bold type is what is entered by the user):



    Enter number 1: 15

    Enter number 2: 27

    Enter number 3: 36

    Enter number 4: 12

    Enter number 5: 9



    The smallest number is: 9

    The second smallest number is: 12


    Do NOT use loops, which we have not yet discussed.

    -----

    If anyone could give me a quick run-down, I would be eternally greatful!
    Thanks in advance!
    1) Get a hold of some good C programming books. Read 'em.
    2) Write some code. Compile often, in a stepwise fashion.
    3) If you run into problems, feel free to post your *detailed* questions here.
    4) Lather, rinse, repeat.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    4
    The reason for posting here is I don't have time to sit down and read a book before this is due. The process of reading a book to be able to do something can be an answer for anything.

    I wrote the flowchart and understand the concept, I just don't understand how to convert the flowchart logic into the syntax of c programming. If I had time to read a book, I wouldn't be asking for a quick walk-through of the given problem.

    My detailed problem: In C, how do I turn lowestnumber1 and lowestnumber2 into an output statement saying that it's lower than the other 3 remaining numbers?

    Thanks.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    1) Create a basic program with the needed headers. I suggest you include:
    Code:
    #include <stdio.h>
    #include <limits.h>
    2) Create three variables:
    Code:
    int smallest = INT_MAX;
    int second_smallest = INT_MAX;
    int input;
    3) Get a one number at a time from the user using:
    Code:
    scanf("%d", &input);
    4) Compare the number you got to the one stored in the variable smallest. If it's not smaller, compare it to second_smallest. Replace the stored number if it's smaller.

    5) Repeat steps 3) and 4) five times.

    6) Print out the result using printf().

    scanf - C++ Reference
    printf - C++ Reference

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    4
    Very helpful, thank you!

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    452
    write it out in pseudocode at least and post that here - we can always help you fix your syntax.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    The reason for posting here is I don't have time to sit down and read a book before this is due.
    Then I'd say you have the wrong idea about the purpose of this forum. If what you really want is someone to do this for you, then hire someone. Otherwise, you'll need to do your own research - just like the rest of us...

    The process of reading a book to be able to do something can be an answer for anything.
    Hmm...you might be onto something there!

    I wrote the flowchart and understand the concept, I just don't understand how to convert the flowchart logic into the syntax of c programming. If I had time to read a book, I wouldn't be asking for a quick walk-through of the given problem.

    My detailed problem: In C, how do I turn lowestnumber1 and lowestnumber2 into an output statement saying that it's lower than the other 3 remaining numbers?

    Thanks.
    Okay, so at least make an attempt to write the program. Or haven't you the time to that either?

  8. #8
    Registered User
    Join Date
    Jun 2010
    Posts
    4
    @Sebastiani
    Cprogramming.com is a web site designed to help you learn the C or C++ programming languages, and provide you with C and C++ programming language resources.

    I just assumed the forums would be the same way. But honestly though, if you took as much time to type out something to get me started, than to put me off, we would be done with this by now.

    But thanks to Memloop for actually being a sport and helping someone out.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by brown287 View Post
    I just assumed the forums would be the same way. But honestly though, if you took as much time to type out something to get me started, than to put me off, we would be done with this by now.
    One of the differences between you and I is that I don't actually care if you get done or not. That means, you have to make the effort to get started, not me. You didn't post anything useful--I don't see your effort. Why should I do it for you? I already know how. I'm not stuck on it, you are. So you need to be the one putting forth effort at learning, not me.

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

  10. #10
    Registered User jephthah's Avatar
    Join Date
    May 2010
    Location
    seattle
    Posts
    49
    Hello, brown287

    Please understand that this forum and others like it are constantly beset by "gimmetehcodezplz" homework-beggars, and to a ridiculous degree.

    just a cursory glance of your initial post shows that you have posted the detailed requirements of a homework assignment, but neglected to post any code or pseudocode to indicate you had made an attempt to start working on this on your own.

    So without making any personal assumptions, your post format exactly follows the MO of a standard homework-beggar.

    Now I'm sorry that you were mis-identified. It does happen occasionally. But consider that while this is your very first experience here, Sebastini in his 10 years and thousands of posts can only refer to the historically overwhelming odds continually turn up in his favor.

    perhaps in the future you'll remember to include a code segment showing what you have done so far, and if possible illustrating where exactly you are stuck... then we can avoid all the wasted time and hurt feelings.

  11. #11
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Honestly a part of what sets a good programmer apart from a mediocre one is how resourceful they are at digging up answers. I mean, you could just google for a basic C program, copy and start modifying it until it does what you need/want. Very little of what you will learn of value will just be handed to you. Discovery is a is a joy in itself.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  12. #12
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by Sebastiani View Post
    1) Get a hold of some good C programming books. Read 'em.
    2) Write some code. Compile often, in a stepwise fashion.
    3) If you run into problems, feel free to post your *detailed* questions here.
    4) Lather, rinse, repeat.
    You do realize this is an infinite loop ?!
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  13. #13
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    Some people do this in their first post:
    1. I have to do this
    2. Here is my code
    3. Please fix it

    That in itself is pretty arrogant and if they even get any replies it is pretty much only to tell them that it doesn't work like that.

    What you've done is equally bad:
    1. I have to do this
    2. Please tell me how / Please do it for me


    But I suppose it's a step up from this, which we also get from time to time:
    1. Write the following for me
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  14. #14
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    Quote Originally Posted by iMalc View Post
    Some people do this in their first post:
    1. I have to do this
    2. Here is my code
    3. Please fix it

    That in itself is pretty arrogant and if they even get any replies it is pretty much only to tell them that it doesn't work like that.

    What you've done is equally bad:
    1. I have to do this
    2. Please tell me how / Please do it for me


    But I suppose it's a step up from this, which we also get from time to time:
    1. Write the following for me
    Other comical variants:

    OP: My program performs X, and now I need to add functionality for Y. Please show me how!
    US: Uh...your program doesn't do X.
    OP: Okay. My program needs to performs X. Please show me how!

    OP: I have written a flight simulation program, but the calculations are coming out wrong! Can someone please edit and fix for me?
    US: You forgot to initialize the 'theta' variable.
    OP: How do I do that?! Sorry, we haven't covered that in class yet!!! BTW: what is the purpose of the 'theta' variable, anyway?
    US: ...so you don't even understand "your" own code???

    Ad nausem...

  15. #15
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    Yeah I like those, Sebastiani.

    OP: My program seems to fail on inserting into a linked list.
    US: It won't even compile. So how come you can even claim it fails on that one issue?
    OP: What's a linked list? What's an error? Who am I?
    US: You clearly hoisted the code and pretended it's yours. Please consider changing your major to underwater basket weaving.

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

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