I have a function that should read in data from a file and add them to and array then i pass that array to another that totals the data then i want to find the average of that array and pass the max value to a variable 'max'
with the code it runs with a runtime error that when i hit ignore it gives me a random value for the output
any ideas would be greatly apprecitated :)
int FindMax()
{
inFile.close();
inFile.open("test.txt");
int dummy, max;
int monthInput[month];
int monthSum[month];
int monthAverage[month];
max = 0;
//stores lineCount variable since it was already pulled in and not needed again
inFile >> dummy;
//pulls in the temperatures for the array to hold the values
for(int i=1; i<=lineCount; i++)
{
inFile >> monthInput[i];
//adds the temperatures together and stores them in monthSum
for(int j=1; j<=month; j++)
{
monthSum[j] = monthInput[i] + monthSum[j];
}
}
//calculates the average temperature after all the temperatures are summed
for(int i=1; i<=month; i++)
{
monthAverage[i] = monthSum[i] / month;
}
//compares the values to find the max average temperature
for(int i=1; i<=month; i++)
{
monthAverage[i];
if(monthAverage[i] > max)
{
max = monthAverage[i];
}
}