Ok first of all I would suggest you use a variable to hold the size of your array like so
1 2 3 4 5 6 7
|
const int SIZE = 10;
int main()
{
double myArray[SIZE];
// Other stuff
}
|
That way you only need to change 1 place if you need to change the size of the array instead of changing the array size and all the of the for loops.
Also delete this line of code we don't need it
int large, small, temp, i;
we will be declaring the variable when we need them in the program which is better then declaring all the variables at the top.
2) You have a semicolon after you for loop on line 15, 23, and 33. That is making it so it only runs the loop once.
3) You sum and average loop looks ok so no need to change that other then the suggestion in number one.
4)
1 2
|
large =( large< temp) ? temp : large;
small = (small > temp) ? temp : small;
|
Delete them lines of code not sure what you are trying to do there but you don't need them.
5) Now your largest and smallest need's some work. First lets declare the variable to hold both the largest and smallest right before the for loop (Since we don't want to overwrite them every time through the loop.
So something like
1 2 3 4 5
|
// Make it a very large number for smallest
double smallest = 9999999;
// If you are only dealing with positive number make largest 0
// If you have negative numbers make it a very large negative number
double largest = 0;
|
Next we need a loop that will check each element in the array to see if it is the smallest or largest element we have seen so far. When it is done with the looping both largest and smallest will hold the correct values.
Here is the whole thing
1 2 3 4 5 6 7 8 9 10
|
double smallest = 99999999;
double largest = 0;
for (size_t i = 0; i != SIZE; ++i)
{
if (myArray[i] <= smallest)
smallest = myArray[i];
if (myArray[i] >= largest)
largest = myArray[i];
}
|
After that you should be good and can continue adding to the program. Make sure you understand all the changes and why we made them before you move on. If you have anymore question or need help with anything else just let us know and we would be more then happy to help.