C++ Intermediate Help

Write your question here.

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
  
// determine average grade for test
double GradeBook::getAverageGrade()
{
   int total = 0; // initialize total

   // sum grades in array
   for ( int grade = 0; grade < STUDENTS; grade++ )
      total += grades[ grade ];

   // return average of grades
   return static_cast< double >( total ) / STUDENTS;
} // end function getAverage

// find maximum grade
int GradeBook::getMaximum()
{
   int highGrade = 0; // assume highest grade is 0

   // loop through grades array
   for ( int grade = 0; grade < STUDENTS; grade++ )
   {
      // if current grade higher than highGrade, assign it to highGrade
      if ( grades[ grade ] > highGrade )
         highGrade = grades[ grade ]; // new highest grade
   } // end for

   return highGrade; // return highest grade
}

GradeBook.cpp: In member function ‘double GradeBook::getAverageGrade()’:
GradeBook.cpp:205: error: invalid conversion from ‘int*’ to ‘int’
GradeBook.cpp: In member function ‘int GradeBook::getMaximum()’:
GradeBook.cpp:220: error: ISO C++ forbids comparison between pointer and integer
GradeBook.cpp:221: error: invalid conversion from ‘int*’ to ‘int’

Anyone can help me with this error?
what is students?
A constant int
jonnin
the compiler thinks something in there is a pointer.
is grades a ** or reference to *?
Last edited on
array of int pointers int grades[STUDENTS][TESTS];
that is it then.
you cant compare it that way...

if ( grades[ grade ] > highGrade )

should be grades[?][?] > highGrade

but I don't know what your indices mean.
You are comparing an int* to an int, just like it said.
Huh that worked! Thanks!
Topic archived. No new replies allowed.