Help finding the average.

I need help finalizing my code. I cant seem to figure out how to get the average in an array of numbers.

The program prompts the user to enter ten integer values between 1 and 100, determines the smallest and largest values entered by the user as well as the average of all the numbers entered by the user.

This is my code so far...

#include <iostream>
using namespace std;
int main() {

const int SIZE = 10;
int values[SIZE];
int count;
int largest;
int smallest;
cout << "\nEnter ten integers between 1 and 100, and I will tell you the smallest, the largest, and the average:" ;
for (count = 0; count < SIZE; count++){

cin >> values[count];
}

largest = smallest = values[0];


for (count =1; count < SIZE; count++) {

if (values[count] > largest)
largest = values[count];
if (values[count] < smallest)
smallest = values[count];
}

cout <<"\nSmallest: "<< smallest ;
cout << "\nLargest: "<< largest ;

system("pause");
return 0;
}
Average is calculated as

(sum of all values) / (number of values)

So you need to declare a variable to store the sum. Set its initial value to zero. Add each value to the sum. Lastly, after you have the sum, divide it by the number of values.

Note: beware of integer division if you want a floating-point result.
Topic archived. No new replies allowed.