### Help with arrays Calculating average c++

I have already written most of the codes. The only thing i am missing is calculating AVERAGE and SUM of the number in .txt file.

numbers in the .txt file are :47
89
65
36
12
25
17
8
62
10
87
62

If anyone can help, it would be much appreciated.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115`` ``````// This program lets the user enter a filename. #include #include #include using namespace std; int getLowest(const int[], int); int getHighest(const int[], int); int main() { ifstream inputFile; string filename; int number; const int ARRAY_SIZE = 12; // Array size int numbers[ARRAY_SIZE]; // Array with 100 elements int count = 0; int lowestNumber, highestNumber , sumNumber=0; // Get the filename from the user. cout << "Please enter the name of the file to read numbers for Number Analysis Program:\n"; cin >> filename; // Open the file. inputFile.open(filename); // If the file successfully opened, process it. if (inputFile) { // Read the numbers from the file and // display them. while (count < ARRAY_SIZE && inputFile >> numbers[count]) count++; // Close the file. inputFile.close(); // Display the numbers read. cout << "The numbers are: "; for (int index = 0; index < count; index++) cout << numbers[index] << " "; cout << endl; } else { // Display an error message. cout << "Error opening the file.\n"; } for (int i = 0; 1 < ARRAY_SIZE; i++) { sumNumber += numbers[i]; } cout << "The sum of the numbers are: " << sumNumber << endl; // Get the lowest test score. highestNumber = getHighest(numbers, ARRAY_SIZE); lowestNumber = getLowest(numbers, ARRAY_SIZE); system("pause"); return 0; } int getLowest(const int array[], int size) { int lowest; // To hold the lowest value // Get the first array's first element. lowest = array[0]; // Step through the rest of the array. When a // value less than lowest is found, assign it // to lowest. for (int count = 1; count < size; count++) { if (array[count] < lowest) lowest = array[count]; } cout << "The lowest nuber is " << lowest << endl; // Return the lowest value. return lowest; } int getHighest(const int array[], int size) { int highest; // To hold the lowest value // Get the first array's first element. highest = array[0]; // Step through the rest of the array. When a // value less than lowest is found, assign it // to lowest. for (int count = 1; count < size; count++) { if (array[count] > highest) highest = array[count]; } cout << "The highest nuber is " << highest << endl; // Return the lowest value. return highest; } ``````
After the loop on line 33 you should use `count` not `ARRAY_SIZE`.

 The only thing i am missing is calculating AVERAGE and SUM of the number in .txt file.
Um? `sumNumber` already contains the sum. You need to divide it by `count` and you will have the average.

By the way: See line 16. The size of the array is not 100.
Registered users can post here. Sign in or register to post.