arrays and pointer

Hey guys, I am working on a project that has a bunch of arrays and pointers. The program reads students from a classroom and every students has 10 different quizzes. So program will calculate the average score of every single student and additionally it will calculate the average of every single quiz.

I have been getting this compiler error that one the function(fillArray) is not able to convert. I have been getting the error in the below.

error: cannot convert 'int (*)[3]' to 'int*' for argument '1' to 'void fillArray(int*, int, int&)

and here is my complete codes. Can anyone help me please?

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
 #include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

const int numberStudent=4, numberQuiz=3;

void fillArray( int a[], int size, int & numberUsed);

void computeStAve(const int grade[] [numberQuiz],double stAve[]);

void computeQuizAve(const int grade[] [numberQuiz], double quizAve[]);

void display(const int grade[][numberQuiz], const double stAve[], const double quizAve[] );


int main()
{
    int numberUsed;
    int grade[numberStudent][numberQuiz];
    double stAve[numberStudent];
    double quizAve[numberQuiz];

    fillArray(grade, numberQuiz, numberUsed);

    computeStAve(grade, stAve);
    computeQuizAve(grade, quizAve);
    display(grade, stAve, quizAve);

    return 0;
}

void fillArray(int a[], int size, int&numberUsed)
{
    cout<<"Enter up to "<<size<<"nonnegative whole numbers.\n"
            <<"Mark the end of the list with a negative number.\n";

            int next, index=0;
            cin>>next;

            while((next>=0) && (index<size))
            {
                a[index]=next;
                index++;
                cin>>next;
            }

            numberUsed=index;
}
void computeStAve(const int grade[][numberQuiz], double stAve[])
{

        for(int stNum=1; stNum<=numberStudent; stNum++)
        {
            double sum=0;

            for(int quizNum=1; quizNum<=numberQuiz; quizNum++)
                sum=sum+grade[stNum-1][quizNum-1];
                stAve[stNum-1]=sum/numberQuiz;
        }
}

void computeQuizAe(const int grade[][numberQuiz], double quizAve[])
{

    for(int quizNum=1; quizNum<=numberQuiz; quizNum++)
    {

        double sum=0;
        for(int stNum=1; stNum<=numberStudent; stNum++)
            sum=sum+grade[stNum-1][quizNum-1];

            quizAve[quizNum-1]=sum/numberStudent;
    }
}

void display(const int grade[] [numberQuiz], const double stAve[], const double quizAve[])
{
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(1);

    cout<<setw(10)<<"Student"
            <<setw(5)<<"Ave"
            <<setw(10)<<"Quizzes\n";

            for(int stNum=1; stNum<=numberStudent; stNum++)
            {

                cout<<setw(10)<<stNum
                        <<setw(5)<<stAve[stNum-1]<<" ";
                    for(int quizNum=1; quizNum<=numberQuiz; quizNum++)
                        cout<<setw(5)<<grade[stNum-1][quizNum-1];
                    cout<<endl;
            }

            cout<<"Quiz averages= ";
            for(int quizNum=1; quizNum<=numberQuiz; quizNum++)
                cout<<setw(5)<<quizAve[quizNum-1];
            cout<<endl;

}
Tou are trying to pass two-dimensional array to function accepting pointer or single dimension array.

Either make it accept two dimensional array or make grades a single dimensional array.
MiiniPaa. How am I gonna do that? Do you have any sample that I could understand? I got the hint though
1
2
void computeStAve(const int grade[][numberQuiz],double stAve[]);
void fillArray( int a[], int size, int & numberUsed);


const int grade[][numberQuiz] Takes two dimensional array
int a[] Takes one dimensional array

You cannot pass same array to both functions. You need to either make grade to take two dmensional array: void fillArray( int a[][numberQuiz], int size, int & numberUsed); or to get away from two dimensional arrays using one dimensional and rewriting your program.
Alright I just change void fillArray to two dimensional array and implemented into my codes and I recieved this error now...:-S

In function 'void fillArray(int (*)[3], int, int&)':
error: incompatible types in assignment of 'int' to 'int [3]'

a[index]=next; You have two dimensional array, so you need to specify both indexes.
yeah I changed it to void fillArray to this:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

void fillArray( int a[][numberQuiz], int size, int & numberUsed)
{
    cout<<"Enter up to "<<size<<"nonnegative whole numbers.\n"
            <<"Mark the end of the list with a negative number.\n";

            int next, index=0;
            int studentPos;
            cin>>next;

            while((next>=0) && (index<size))
            {
                a[studentPos++][index]=next;
                index++;
                cin>>next;
            }
            numberUsed=index;


}


Topic archived. No new replies allowed.