@histrungalot
Your code is fine and it sure will solve Major Aly's problem. But your code has limitations and can initiate memory leak errors since your AVGPCT* CALC(student *A) function assumes that *A* is an array of five. What if student is a pointer to an array of less than 5 students?
To make the code dynamic, write it this way:
AVGPCT* CALC(student *A, int cStudents)
{
int x,y;
//---------------------------------------
// Have to allocate the memory here
AVGPCT *D = new AVGPCT[cStudents];
for(x=0;x<cStudents;x++)
{
D[x].avg = 0;
D[x].pct = 0;
for(y=0;y<3;y++)
{
D[x].avg+=A[x].SUB[y];
D[x].pct+=A[x].SUB[y];
}
}
for(x=0;x<cStudents;x++)
{
//---------------------------------
// I changed the value here to 3
// because there are 3 grades
D[x].avg/=3;
D[x].pct/=300;
}
return (D);
}
And call it this way:
student S[5];
AVGPCT *D = CALC(S, 5);
...