I'm supposed to write my results to two files, and it doesn't seem to be working at all. With my code below, what's my problem. Please answer ASAP! Thanks for all of the help in advance!
Code:
void OpenOutputFile(ofstream&, string);
int main()
{
ifstream indiv_file;
ofstream ofs_max;
ofstream ofs_average;
int array[MAX_SIZE], next, count = 0;
float average_temp, maximum_temp;
int array_size;
string dir, out_file_max = "MaxsOfArrays.txt", out_file_average = "AvgsOfArrays.txt";
cout.precision(0);
cout << "Enter directory with files available for use: "; //Lists the files in the current directory you could input .
cin >> dir;
stringVector files = stringVector();
OpenOutputFile (ofs_max, out_file_max);
OpenOutputFile (ofs_average, out_file_average);
getDir (dir, files);
int fsize = files.size();
for (unsigned int i = 0; i < fsize; i++)
{
count = 0;
if (files[i].at(0)!= '.') // if the file is a valid file
{
//cout << endl << dir + files[i];
OpenInputFile (indiv_file, (dir + files[i]));
array_size = ReadArray(indiv_file, array);
average_temp = CalcAverage(array, array_size);
maximum_temp = CalcMax(array, array_size);
/* for (int j = 0; j < array_size; j++) // If you want to read out the data
{
cout << array[j] << " ";
} */
files[i].erase(files[i].find("."), 5); //Deletes anything after AND including the 'dot' in the filename.
cout << endl << "The average temperature in " << files[i] << " was: " << average_temp << endl;
cout << "The maximum temperature in " << files[i] << " was: " << maximum_temp << endl;
ofs_max << "The maximum temperature in " << files[i] << " was: " << maximum_temp << endl;
ofs_average << "The average temperature in " << files[i] << " was: " << average_temp << endl;
}
indiv_file.close();
ofs_max.close();
ofs_average.close();
}
cout << endl;
return 0;
}
void OpenOutputFile(ofstream &out_file, string file_name)
{
out_file.open("MaxsOfArrays.txt");
out_file.open("AvgsOfArrays.txt");
}