I am trying to compile the following code and I keep getting a reference error for my output file through a function. The purpose of the program is to read a file, sort through arrays, and output into a certain form. I am sure it is something small, but I do not understand what I am doing wrong. Thanks in advanced for any help.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int runners = 5;
const int days = 7;
void readFile(ifstream& infile, string names[], double miles[runners][days]);
void fileOutput(ofstream& outfile, string names[], double miles[days], double
averageMiles[days]);
void calcMiles(string names[], double miles[][days], double averageMiles[days]);
main ()
{
string names[runners];
double day[runners][days];
double milesDays[days];
double average[runners];
ifstream inputFile;
ofstream outputFile;
cout << "Runners Log" << endl;
inputFile.open("data.txt");
outputFile.open("newfile.txt");
readFile(inputFile, names, day);
calcMiles(names, day, average);
fileOutput(outputFile, names, milesDays, average);
inputFile.close();
outputFile.close();
return 0;
}
void readFile(ifstream& infile, string names[], double miles[][days])
{
for(int i = 0; i < runners; i++)
{
infile >> names[i];
for(int j = 0; j < days; j++)
{
infile >> miles[i][j];
}
}
}
void fileOutput(ofstream& outfile, string names[], double miles[][days], double
averageMiles[days])
{
double avg = 0;
outfile << "Runners Log" << endl;
outfile << "Results" << endl;
outfile << setw(10) << "Name" << setw(10) << "Day 1"
<< setw(10) << "Day 2" << setw(10) << "Day 3" <<
setw(10) << "Day 4" << setw(10) << "Day 5" << setw(15) << "Average Miles" << setw(10) << endl;
for(int i = 0 ; i < runners; i++)
{
outfile << setw(10) << names[i];
for(int j = 0; j < 7; j++)
{
outfile << setw(10) << miles[i][j];
}
outfile << setw(15) << averageMiles[i] << setw(10) << miles[i] << endl;
}
// Calculate and display class average
for(int i = 0; i < runners; i++)
avg += averageMiles[i];
avg /= runners;
outfile << endl << "Runners Average: " << setprecision(2) << avg << endl;
}
void calcMiles(string names[], double miles[][days], double averageMiles[days])
{
double average;
for(int i = 0; i < runners; i++)
{
average = 0;
for(int j = 0; j < days; j++)
{
average += miles[i][j];
}
average = (double)average/days;
averageMiles[i] = average;
}
}