Try and follow this it should work
Code:
#include <fstream.h>
#include <iostream.h>
#include <cstdlib>
void calcScore(ifstream& input, ofstream& output);
int main()
{
ifstream Gradebook1;
ofstream Gradebook2;
Gradebook1.open("grades.dat");
if(Gradebook1.fail())
{
cout<<"Error opening Input File.\n";
exit(1);
}
Gradebook2.open("grades2.dat");
if (Gradebook2.fail())
{
cout<<"Error opening Output File.\n";
}
calcScore (Gradebook1, Gradebook2);
Gradebook1.close();
Gradebook2.close();
return 0;
}
void calcScore(ifstream& input, ofstream& output)
{
char full_name [40];
int mark;
int counter=0;
double sum=0;
while (counter < 5)
{
for (int i=0;i<12;i++)
{
if(i<=1)
{
input>>full_name;
output<<full_name<<" ";
}
else
{
input>>mark;
sum+=mark;
output<<mark;
}
}
output<< (sum/10)<<endl;
sum =0;
counter++;
}
}
And for the files try using
grades.dat (Before program is run)
Parker Peter 80 76 90 56 72 65 78 98 84 62
Kent Clark 65 76 82 45 92 83 72 75 80 69
Lang Lana 98 92 89 83 76 77 65 62 88 76
Wayne Bruce 90 98 65 45 78 92 92 58 67 74
Kyle Helena 65 64 82 54 58 52 62 45 90 79
Grades2.dat (After program is run)
Parker Peter 80 76 90 56 72 65 78 98 84 62 76.1
Kent Clark 65 76 82 45 92 83 72 75 80 69 73.9
Lang Lana 98 92 89 83 76 77 65 62 88 76 80.6
Wayne Bruce 90 98 65 45 78 92 92 58 67 74 75.9
Kyle Helena 65 64 82 54 58 52 62 45 90 79 65.1
don't ask about the names!