#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
double average(int sum, int numElms)
{
int i;
double avg;
avg = sum/numElms;
return sum;
}
int main()
{
ifstream fileIn;
const int MAX_ARRAY = 500;
int scores[MAX_ARRAY];
int numElms, sum;
int i;
fileIn.open("pgm5data.txt"); //open file
if (fileIn.fail() )
{
cout << "Error opening file";
exit(-1);
}
i = 0;
fileIn >> scores[i];
while (!fileIn.eof() && i < MAX_ARRAY)
{
i++;
fileIn >> scores[i];
sum+=scores[i];
}
numElms = i;
cout << "\nSum is: " << average(sum, numElms);
return 0;
}
I don't understand why im getting huge numbers that aren't anywhere close to what I need. Advice? thanks!