Hey back again, okay so the program is to read in a file that has 10 students names with 5 test scores for each of them. The file looks like this:
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 74 63
Then I am suppose to write it to a new file which is suppose to look like this:
Student Test1 Test2 Test3 Test4 Test5 Average Grade
( the names and test scores with the average and the average turned into a letter grade)
I started off with like 35+ errors, got it down to like 2, well here's the program and the errors:
ERRORS:
1>c:\users\welcome back\documents\visual studio 2008\projects\file\file\file input.cpp(59) : error C2065: 'total' : undeclared identifier
1>c:\users\welcome back\documents\visual studio 2008\projects\file\file\file input.cpp(60) : error C2448: 'calc_grade' : function-style initializer appears to be a function definition
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 74 63
Then I am suppose to write it to a new file which is suppose to look like this:
Student Test1 Test2 Test3 Test4 Test5 Average Grade
( the names and test scores with the average and the average turned into a letter grade)
I started off with like 35+ errors, got it down to like 2, well here's the program and the errors:
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void calcAvg(ifstream& in_file, ofstream& out_file, float& avg);
char calc_grade(float avg);
int main() {
ifstream inp;
ofstream outp;
inp.open("Ch07_Ex09Date.txt");
outp.open("Ch07_Ex09OUT.txt");
outp << "Student Test1 Test2 Test3 Test4 Test5 Average Grade";
string name;
float classAvg = 0;
char grade;
int k;
float avg;
for (k=1; k<=10; k++)
{
inp >> name;
outp << setw(10) << name;
calcAvg(inp, outp, avg);
outp << setw(6) << avg;
classAvg = classAvg + avg;
grade = calc_grade(avg);
outp << setw(5) << " " << grade << endl;
}
classAvg = classAvg / 10;
outp << endl << "Class Average = " << classAvg;
return 0;
}
void calcAvg(ifstream& inp, ofstream& outp, float& avg)
{
int score, k;
float sum = 0.0;
for (k=1; k<=5; k++)
{
inp >> score;
outp << setw(4) << score << " ";
sum = sum + score;
}
avg = sum / 5;
}
char calc_grade(total)
{
if (total >= 0)
if (total >= 60)
if (total >= 70)
if (total >= 80)
if (total >= 90)
if (total > 100)
cout << "Grade can not exceed 100" << endl;
else
cout << "A" << endl;
else
cout << "B" << endl;
else
cout << "C" << endl;
else
cout << "D" << endl;
else
cout << "F" << endl;
else
cout << "Grade can not be a negative number" << endl;
}
ERRORS:
1>c:\users\welcome back\documents\visual studio 2008\projects\file\file\file input.cpp(59) : error C2065: 'total' : undeclared identifier
1>c:\users\welcome back\documents\visual studio 2008\projects\file\file\file input.cpp(60) : error C2448: 'calc_grade' : function-style initializer appears to be a function definition