Hello. I am in a beginning C++ programming course in which we have just finished loops. I have been asked to plan, code, and execute a program to do the following things: Ask the user for the file name, then calculate an average of the numbers and display two lists of numbers, one of which will display the numbers less the average and the other displaying numbers greater than or equal to the average. The amount of numbers on the files is unknown. I have written the first part to input numbers from the file and to calculate an average but it does nothing and I can't figure out why. Any help whatsoever will be greatly appreciated.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
ifstream inData;
ofstream outData;
int avgcounter = 0;
float number, sum = 0, average;
char filename[256];
int main()
{
cout << "Please enter the name of the file." << endl;
cin >> filename;
inData.open(filename);
while(!inData.eof())
{
inData >> number;
sum = number + sum;
average = sum / avgcounter;
avgcounter++;
}
cout << "The average is " << average << '.';
return 0;
}