Keep getting -fpermissive errors on my program

Basically, the output of my program is supposed to be like this:
The class scores are:
Students # Test#1 Test#2 Test#3
1 88 98 76
2 76 88 87
3 56 77 55
4 55 89 66
5 76 98 66
6 87 84 81
7 80 91 77
8 69 70 81
9 85 99 77
10 88 91 79

The class average for test #1 is : ?
The class average for test #2 is : ?
The class average for test #3 is : ?

The problem is that whenever I run my code I get these errors:
[Error] invalid conversion from 'int' to 'int (*)[3]' [-fpermissive]
[Error] initializing argument 1 of 'double ClassAvg(int (*)[3], int)' [-fpermissive]
[Error] invalid conversion from 'int' to 'int (*)[3]' [-fpermissive]
[Error] initializing argument 1 of 'double ClassAvg(int (*)[3], int)' [-fpermissive]
[Error] invalid conversion from 'int' to 'int (*)[3]' [-fpermissive]
[Error] initializing argument 1 of 'double ClassAvg(int (*)[3], int)' [-fpermissive]
[Error] expected ';' before 'cout'
global scope:
[Error] expected declaration before '}' token

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
  //Compute a program that declares and initializes a two dimensional array called scores
#include<iostream>
#include<iomanip>
using namespace std;
const int testNum=3;
const int scores=10;
 double ClassAvg(int scores[10][3], int testNum);
 
 int main()
 {
 	double CAvg1,CAvg2,CAvg3;
 	int table[scores][testNum]={{88,98,76},
	                           {76,88,87},
							   {56,77,55},
							   {55,89,66},
							   {76,98,66},
							   {87,84,81},
							   {80,91,77},
							   {69,70,81},
							   {85,99,77},
							   {88,91,79} };
							   
  CAvg1=ClassAvg(scores,0); 
  CAvg2=ClassAvg(scores,1);
  CAvg3=ClassAvg(scores,2);							   	
  
    cout<<"The class scores are:\n";
    
    ClassAvg(table,scores)
  	cout<<setw(5)<<"Students #"<<setw(7)<<"Test #1"<<setw(7)<<"Test #2"<<setw(7)<<"Test #3"<<endl;
  	
  	cout<<"The class average for test#1 is: "<<CAvg1<<endl;
  	cout<<"The class average for test#2 is: "<<CAvg2<<endl;
  	cout<<"The class average for test#3 is: "<<CAvg3<<endl;
  	
  	return 0;
  }
   double ClassAvg(int array[][testNum], int numRows)
   {
   	 for(int row=0;row<numRows;row++)
   	 {
   	 	for(int col=0;col<testNum;col++)
   	 	{
   	 		cout<<setw(5)<<array[row][col]<<" ";
   	 	}
   	 	cout<<endl;
   	 }
   }
 }
Your ClassAvg() function expects a two dimensional array of int for the first parameter yet you're trying to pass a single int instead. You probably mean to pass the table, not scores.

I mean, I kept the ClassAvg(table,scores) and took out some other things, and it did give me the table with the students' test scores, but idk how to show the class average scores: This is the simplified code that worked, but doesnt show the class averages:

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
//Compute a program that declares and initializes a two dimensional array called scores
#include<iostream>
#include<iomanip>
using namespace std;
const int testNum=3;
const int scores=10;
 double ClassAvg(int scores[10][3], int testNum);
 
 int main()
 {
 	int table[scores][testNum]={{88,98,76},
	                           {76,88,87},
							   {56,77,55},
							   {55,89,66},
							   {76,98,66},
							   {87,84,81},
							   {80,91,77},
							   {69,70,81},
							   {85,99,77},
							   {88,91,79} };
							   
 						   	
  
    cout<<"The class scores are:\n";
    
    ClassAvg(table,scores);
  	
  	return 0;
  }
   double ClassAvg(int array[][testNum], int numRows)
   {
   	 for(int row=0;row<numRows;row++)
   	 {
   	 	for(int col=0;col<testNum;col++)
   	 	{
   	 		cout<<setw(5)<<array[row][col]<<" ";
   	 	}
   	 	cout<<endl;
   	 }
   }
 
What exactly are you trying to average? The rows like {88, 98, 76} or the columns 88, 76, 56, 55, 76, etc?

the columns, 88,76,56,55,76, etc
Okay then you only need one loop to loop through the columns. The rows will be constant throughout the function. Something more like:

1
2
3
4
5
6
7
8
double ClassAvg(int array[scores][testNum], int column)
{

      for(int i = 0; i < scores; i++)  // You may want to actually pass "scores" as a parameter as well. 
      {
         cout << setw(5) << array[i][column] << " ";
      }
      cout << endl;


But instead of printing the numbers, you'd sum them, then average them and then return the average.

And you may want to start adding a little bit of whitespace in your "calculations" to make reading the code easier.
Topic archived. No new replies allowed.