I kind of abandoned the entire dynamic array path by setting the array to the hypothetical max of [250][8].
Using dynamic arrays opened up a whole host of problems that I am just not smart enough to deal with.
However, I'm having a problem with another part of the same program, if you guys can help me out with this.
The point is to take the "class average," that is, adding up the averages of each individual 'Project' dimension in the array and then dividing it by 8, or the size of the 'Project' dimension.
The code I've got:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
int Avg2; //Avg2, Sum2, etc., is just to differentiate between the other Avg variables in the program
int Sum2=0;
float AvgT2;
float SumT2=0;
for(int j=0; j<=Projects; j++){
for(int i=0; i<=Students; i++) {
Sum2 = Sum2 + Grades[i][j];
}
Avg2 = Sum2/Students;
}
SumT2 = SumT2 + Avg2;
AvgT2 = SumT2/Projects;
cout << AvgT2 << endl;
|
comes out with values approximately one half of one percent higher than they should be (eg., 47.75 instead of 47.5), which is so close that I am left absolutely baffled, and the weirdest part is that it follows the format of a previous Averaging function, which comes out with the
correct result and looks like this:
1 2 3 4 5 6 7 8 9 10
|
int Select;
float Avg1;
float Sum1=0;
cout << "Give the number of the project: ";
cin >> Select;
for(int i=0; i<=Students; i++) {
Sum1 = Sum1 + Grades[i][Select];
}
Avg1 = Sum1/Students;
cout << Avg1 << endl;
|
So one of these things is obviously wrong. Maybe the second is performing correctly in
spite of something, or maybe I overlooked something in the first, but, either way I'm stuck now. Any help?