2d array grades evaluation

I have to write program to evaluate students' grades in class of size that user determines.I have to
find and print students' average in class.
find and print average for each exam
find and print highest score for each exam
Find and print how many grades are below,above and equal to an average for each exam
Find and print overall average for class
When i run program it just asks me to enter scores infinite times don't know where possibly can be a mistake. Thank you very much in advance



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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>

using namespace std;
const int SIZE=50,NUMTEST=4;
double findexamavg(int grades[][NUMTEST], int classsize);
void findhighscore(int grades[][NUMTEST], int classsize);
void findstudavg(int grades[][NUMTEST], int classsize);
void countermarks(int grades[][NUMTEST], int classsize);
int main()
{
    int grades[SIZE][NUMTEST],classsize,stnum,test;
    double exavg[NUMTEST],classavg,sum=0;
    cout<<"How many students in class?"<<endl;
    cin>>classsize;
    //Read in data
    cout<<"Please enter studnts' grades"<<endl;
    for(stnum=0;stnum<classsize;stnum++)
     {
       for(test=0;test=NUMTEST;test++)
         cin>>grades[stnum][test];
     }
     //Printing test average
     for(test=0;test<NUMTEST;test++)
       cout<<"test number "<<test<<"had an average of "<<findexamavg(grades,classsize)<<endl;

     //Printing Students' individiual average
     findstudavg(grades,classsize);
     for(test=0; test<NUMTEST;test++)
      {
       exavg[test]=findexamavg(grades,classsize);
       sum+=exavg[test];
      }

      classavg=(double)sum/NUMTEST;
      cout<<"Overall class average is "<<classavg<<endl;
    return 0;
}
// Find  and print each exam's average and return to calling function
double findexamavg(int grades[][NUMTEST], int classsize)
{
    int sum=0,stnum,test;
     double exavg;

    for(test=0;test<NUMTEST;test++)
     {
         sum=0;
         for(stnum=0;stnum<classsize;stnum++)
            sum+=grades[stnum][test];
         exavg=(double)sum/classsize;

     }
        return exavg;

}
// Find  and print each studet's average 
void findstudavg(int grades[][NUMTEST], int classsize)
{
    int sum=0,stnum,test;
     double stavg;

     for(stnum=0;stnum<classsize;stnum++)
     {
         sum=0;
         for(test=0;test<NUMTEST;test++)
            sum+=grades[stnum][test];
         stavg=(double)sum/NUMTEST;
         cout<<"student number "<<stnum<<"had an average of "<<stavg<<endl;

     }
        return ;

}
//Find and print highest score for each exam
void findhighscore(int grades[][NUMTEST], int classsize)
{
    int stnum,test;
    for(test=0;test<NUMTEST;test++)
     {
         int highscore=grades[0][test];

         for(stnum=0;stnum<classsize;stnum++)
           {
            if(highscore<grades[stnum][test])
              highscore=grades[stnum][test];
           }
       cout<<"Highest score for test number "<<test<<" is "<<highscore<<endl;
     }
     return;
}
//Find and print how many grades above,below and equal to average for each exam
void countermarks(int grades[][NUMTEST], int classsize,int &numless,int &numgr,int &numeq)
{
   int stnum,test;
   double exavg;
   for(test=0;test<NUMTEST;test++)
     {
         numgr=0;
         numless=0;
         numeq=0;
         exavg=findexamavg(grades,classsize);
         for(stnum=0;stnum<classsize;stnum++)
            if(grades[stnum][NUMTEST]<exavg)
              numless++;
            else if(grades[stnum][NUMTEST]>exavg)
              numgr++;
            else
             numeq++;
       cout<<"the number of grades greater than average in exam "<<test<<" is "<<numgr;
       cout<<" less than average is "<<numless<<" and number of grades which are equal to the average is "<<numeq<<endl;
      }

  return;
}
Last edited on
1
2
for(test=0;test=NUMTEST;test++)
         cin>>grades[stnum][test];


that for loop doesn't have an escape clause. You are assigning test to NUMTEST which will always return boolean true.
thanks very much.
Topic archived. No new replies allowed.