newbie needs help on small program

This is a discussion on newbie needs help on small program within the C Programming forums, part of the General Programming Boards category; I am teaching myself and need to create a program:
that will read in five positive integers (one at a ...

newbie needs help on small program

I am teaching myself and need to create a program:

that will read in five positive integers (one at a time) and print out the largest and smallest number of the 5 numbers. The program should read the numbers 1 at a time.
Also I need this program such that it takes an unlimited amount of positive integers.

- Put the computer aside for the moment, and grab a pen and paper
- Solve the problem by hand, keeping note of each step you must take
- Do this a few times until you have a list of steps to follow
- Open your source file
while(!complete)
{
- Write a few lines of code to do just one thing
- Compile and run this code to ensure it is doing what you expect
}

My recommendation: Start with the "5 input" variation first, this will be easier.

Step 1: Write the basic framework of the program (which you have in your first post, but don't include the "for()" loop).

Step 2: Write a loop that simply receives user input and places it into your array, and loop it 5 times. Compile and verify there are no errors or warnings.

Step 3: Write a loop that prints each element of that array, so you can see the results. Even if you don't require this output as part of your program, it will help you verify that your code is working as expected. (Coding is like constructing a building, in that it often requires the assembly of temporary "scaffolding" to help achieve the main goal). Compile and verify there are no errors or warnings.

Step 4: Write the code that searches for the largest number, and prints it out. Compile and verify there are no errors or warnings.

Step 5: Write the code that searches for the smallest number, and prints it out. Compile and verify there are no errors or warnings.

Take it step by step. If you get stuck, feel free to ask additional questions - ensure that those questions are specific if you want good, specific answers.

- Put the computer aside for the moment, and grab a pen and paper
- Solve the problem by hand, keeping note of each step you must take
- Do this a few times until you have a list of steps to follow
- Open your source file
while(!complete)
{
- Write a few lines of code to do just one thing
- Compile and run this code to ensure it is doing what you expect
}

My recommendation: Start with the "5 input" variation first, this will be easier.

Step 1: Write the basic framework of the program (which you have in your first post, but don't include the "for()" loop).

Step 2: Write a loop that simply receives user input and places it into your array, and loop it 5 times. Compile and verify there are no errors or warnings.

Step 3: Write a loop that prints each element of that array, so you can see the results. Even if you don't require this output as part of your program, it will help you verify that your code is working as expected. (Coding is like constructing a building, in that it often requires the assembly of temporary "scaffolding" to help achieve the main goal). Compile and verify there are no errors or warnings.

Step 4: Write the code that searches for the largest number, and prints it out. Compile and verify there are no errors or warnings.

Step 5: Write the code that searches for the smallest number, and prints it out. Compile and verify there are no errors or warnings.

Take it step by step. If you get stuck, feel free to ask additional questions - ensure that those questions are specific if you want good, specific answers.

Thanks Matticus, this was a big help to get me started. I guess I came across in the wrong way. I didn't expect someone to just straight write the whole code for me. I just needed some suggestions.
My biggest issue I have run across was the code for searching for the lowest and highest integer.

I have not gotten to this part yet, but I am guessing I will use an if-else structure. I suppose I can assign each of the 5 integers an abstract letter eg. a, b, c, d e, then use if a< b type code. Or maybe I also need a switch/case structure.

I would expect you to use a loop to loop over the elements of the array. Creating separate variables for each of the 5 integers would be a wrong approach. (Well, it can work here, but is completely infeasible when you can potentially have a billion integers.)

I would expect you to use a loop to loop over the elements of the array. Creating separate variables for each of the 5 integers would be a wrong approach. (Well, it can work here, but is completely infeasible when you can potentially have a billion integers.)

Alright here is what I came up with even though I know there is a shorter way.