### Why Won't This Show Correct Average? Everything runs fine so far. It reads from an option of 2 different files provided by my professor in his compiler containing various numbers. I just don't know how to average them all correctly. I think the "average = (sum / counter);" might be in the wrong spot. Thank you.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162`` ``````#include #include #include #include using namespace std; int main() { int counter = 0; double numberArray, sum = 0, average = 0; ifstream file; string fileChoice, data1 = "data1.txt", data2 = "data2.txt"; cout << setprecision(2) << fixed; cout << "Please enter the file name to open: "; cin >> fileChoice; cout << "Reading file: " << fileChoice << endl; if (fileChoice == data1 || fileChoice == data2) { file.open(fileChoice.c_str()); file >> numberArray[counter]; while (file) { counter++; file >> numberArray[counter]; } sum += numberArray[counter]; average = (sum / counter); cout << "There were " << counter << " numbers in the file." << endl; cout << "The average of the numbers was " << average << endl; cout << "Here is your report" << endl; for (int i = 0; i < counter; i++) { if (numberArray[counter] < average) { cout << numberArray[i] << " is below average" << endl; } else if (numberArray[counter] > average) { cout << numberArray[i] << " is above average" << endl; } else if (numberArray[counter] == average) { cout << numberArray[i] << " is exactly average" << endl; } } } else { cout << "Cannot locate the desired file!" << endl; return 0; } }`````` Lines 31 and 32.

Also, look at what you are doing on lines 42, 46, and 50.

Hope this helps.  