I CAN NOT GET THIS TO WORK I THINK IT IS GOING WRONG IN THE INDATE FILES
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;
void calculateAverage (ifstream&, ofstream&, double&);
char calculateGrade (double);
int main ()
{
char grades [15];
double avg, average=0;
int count=0;
string name;
ifstream inFile;
ofstream outFile;
cout << "\n\tProgram that works with files and functions.";
cout << "\n\n\tEnter the input file name : ";
cin >> grades;
inFile.open("G:\\grades.txt");
if (!inFile.is_open("G:\\calGrades.txt"))
{
cout << "\n\n\tError with the input file";
exit (0);
}
cout << "tEnter the output file name :";
cin >> "G:\\calGrades.txt";
outFile.open ("G:\\calGrades.txt");
if (!outFile.is_open("G:\\calGrades.txt"))
{
cout << "\n\n\tError with the input file";
exit (0);
}
outFile << fixed;
outFile .presision(2);
outFile << "Student Test1 Test2 Test3 Test4 Test5 Average Grade";
outFile << endl;
while (true)
{
inFile >> name;
if (!inFile)
break;
outFile << setw(10);
outFile << left;
outFile << name;
calculateAverage (inFile, outFile, avg);
outFile << setw(10);
outFile << right;
outFile << avg;
outFile << setw(6);
outFile << right;
outFile << calculateGrade(avg);
outFile << endl;
count ++;
average += avg;
}
average /= count;
outFile << endl << "Class Average = " << average;
inFile.close ("G:\\grades.txt");
outFile.close ("G:\\calGrades.txt");
return 0;
}
void calculateAverage (ifstream& in, ofstream& out, double& std)
{
int score;
double avg = 0;
for (int i=0; i<5; i++)
{
in >> score;
out << setw(7) << right << score;
avg += score;
}
avg /= 5.0;
}
char calculateGrade (double myAvg)
{
if ( myAvg < 60)
return 'F';
else
if ( myAvg < 70)
return 'D';
else
if (myAvg < 80)
return 'C';
else
if (myAvg < 90)
return 'B';
else
return 'A';
}