Below, I put in the comments on the code some info to help you get start it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
int main()
{
//Declarations
const int SIZE = 20;
string numbers[SIZE]; // You are working with numbers; therefore, switch the string type.
// to a numerical type (i.e. int)
int smallest;
int i = 0;
int userNumber; // You are not using this variable in the program. Do you need it?
// if not, then get rid of it.
//Get User Numbers
for (i = 0; i < SIZE; i++)
{
cout << "Enter 20 Numbers Please: ";
cin >> numbers[i];
//if (numbers[i] < numbers[i + 1]) // This if statement is not need it.
//{
cout << numbers[i]; // I recommend you add the << endl or space to separate the
// numbers during the display.
//}
}
// To find the lowest number in the array.
// - Initialized the smallest variable with the first element of the array.
// - Run a for loop that begins with the second element and will stop at less than
// the size of the elements in the array.
// - Put an if statement inside the for loop to check if the numbers is less than
// the smallest number, then that number will be assigned to the smallest number
// variable.
return 0;
}
|
To find the highest number, it is nearly identical to find the lowest number.
You may need a running total to obtain the total numbers of the array. Hence, the average, as well.
Programs that calculate the total of a series of numbers typically use two elements:
- A loop that reads each number in the series.
- A variable that accumulates the total of the numbers as they are read. The variable that is used to accumulate the total of the numbers is called an
accumulator . It is often said that the loop keeps a running total because it accumulates the total as it reads each number in the series.
So the average will be the running total variable / total number of elements
I hope it helps.
Edited: integralfx gives you a great example.