1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <conio.h>
using namespace std;
void capacity();
int main()
{
int ROW = 25;
const int COL = 4;
const int nameCOL = 5;
double ClassAvetest;
int test[ROW][COL];
int totaltest;
char name[ROW][nameCOL][30],grade;
int total = 0;
double studentave;
ifstream inputFile;
inputFile.open("classdata.txt");
if (!inputFile)
cout << "Error opening file.n";
else
{
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
inputFile >> test[i][j];
for (int j = 4; j < nameCOL; j++)
inputFile.getline(name[i][j], 30);
if(inputFile.eof())
{
ROW=i;
break;
}
}
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
cout << test[i][j] << " " ;
for (int j = 4; j < nameCOL; j++)
cout << name[i][j]<< endl;
for (int j = 0; j < COL; j++)
total += test[i][j];
studentave = float(total)/4;
cout << "Test Average:"<< setprecision(2) << fixed << studentave;
total = 0;
switch((int)studentave/10 )
{
case 10 :
case 9 : grade = 'A'; break;
case 8 : grade = 'B'; break;
case 7 : grade = 'C'; break;
case 6 : grade = 'D'; break;
default : grade = 'F';
}
cout << " Grade: " << grade << endl;
cout << endl;
}
for (int j = 0; j < COL; j++)
{
totaltest = 0;
for (int i = 0; i < ROW; i++)
totaltest += test[i][j];
ClassAvetest = float(totaltest)/ROW;
cout << "Class Average Test" << (j+1) << setprecision(2) << fixed << " "<< ClassAvetest << endl;
}
inputFile.close();
}
getch();
return 0;
}
|
not quite understanding the error, when i try to make constant it gives me many more errors. Any help would be appreciated.
1 2
|
Error E2313 a.cpp 14: Constant expression required in function main()
Error E2313 a.cpp 16: Constant expression required in function main()
|
here is the txt file:
92 83 91 89 John Centeno
75 73 79 77 Stuart Morris
65 82 83 77 Robert Cifuentes
93 95 91 92 Miguel Kuey
84 87 92 81 Monica Liao
66 65 77 78 Linda Gonzalez
72 66 91 88 James Waggoner
68 62 77 58 Luis Amezcua
77 89 83 81 Arnoldo Ramos
92 83 95 93 Kathryn Yescas
73 78 82 75 Sylvia Shin
77 73 78 76 Tony Balogun
82 83 88 84 Yonjhen Sutoyo
66 72 64 68 Damon Vertido
79 82 85 77 Michelle Valdez
83 93 95 94 Maria Villamor
63 62 69 73 Erika Morris
88 83 84 79 Alonso Baek
82 86 91 83 Hye Dizon
75 79 82 73 Olarewaju Nayak
88 93 92 93 Albert Lane
89 95 96 90 Joseph Alan
77 75 82 78 Gerard Cendejas