Need help with Program

This is a discussion on Need help with Program within the C Programming forums, part of the General Programming Boards category; Hey, First off, I'm new to C programming and am having trouble with an assignment that involves sorting numbers that ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    1

    Need help with Program

    Hey,

    First off, I'm new to C programming and am having trouble with an assignment that involves sorting numbers that are input by the user. The requirements for the program must be:

    -to read some positive numbers from the keyboard. use ": " for a prompt
    -when the user types 0, the program stops reading numbers
    -sort the numbers into ascending sequence, and print them one number per line
    -sort the numbers into descending sequence, and print them one number per line
    -print a line of 10 dashes before the first set of numbers, between the two sets of numbers and after the last set of numbers
    -use a separate function to print the numbers
    -use two separate functions to sort the numbers
    -and it must handle an arbitrary number of numbers

    Now, I've started and restarted writing this program several times, but have gotten nowhere. I am thinking that i will be using an insertion sort, but i'm having trouble figuring out how it will handle an arbitrary number of numbers. Thanks in advance for the help.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by irontitan76 View Post
    Now, I've started and restarted writing this program several times, but have gotten nowhere.
    There's your problem in a nutshell... you are thinking about source code and C programming... but you're not ready for that just yet.

    First step... understand the problem itself... exactly what is required of you ... Yes it's spelled out nicely in human terms, but you need to think down to the computer's level to actually understand the bits and pieces of the assignment...

    For example... "read some positive numbers from the keyboard" ... what exactly do you have to do to do that? You can't just look at the computer and say... "Ask me for 10 numbers..." can you.

    So you need to understand what that means at the computer's level... Ok, you say... I need to read from the keyboard ... but where do I put these numbers once I get them, how do I organize them what do they mean and what do I have to do with them...

    So... once you have it down to sufficiently small blobs...

    You start to plan out how you're going to solve the problem... Write a step by step procedure a total flaming idiot (the computer) can follow that solves the problem.

    Now from your plan... start composing your code --note this is the first time you worry about source code-- work in small steps testing as you go... Get your inputs working, get it storing the numbers, etc...

    Once the program is finished spend some time testing it... type in garbage, see what happens, don't put in anything... etc.

    Voila... one working program.


    If you run into problems along the way... post your code and we'll see what we can do...

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Because as the user enters the numbers, your program will count how many are entered, and have to save them to an array.

    I'd switch from insertion sort, to bubble sort. Insertion sort is more integrated, and it will be more difficult to split it into two functions, as required. Substitution sort is just like (almost) bubble sort, in case you prefer it.

    Post up your code after you've studied the problem, and let's see where you're at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-16-2010, 10:17 AM
  2. Replies: 1
    Last Post: 03-03-2009, 03:47 PM
  3. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  4. Replies: 18
    Last Post: 11-13-2006, 12:11 PM
  5. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 11:53 AM

Tags for this Thread


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