variable not declared in this scope

I'm basically supposed to find the the average of the course and the individual average and stuff, but I'm stuck on the course average. My other functions work, but my course average isn't working.

student_num not declared
quiz_num not declared
invalid types void(*)[256]double for array subscript.

These are all on my course average function.

How would I fix it?

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

using namespace std;

const int number_quizzes = 100;
const int students =5;

void ind_avg(const int grade[][number_quizzes] , double student_avg[]);
//this gets the individual average of students.
void test_avg(const int grade[][number_quizzes], double quiz_avg[]);
//this gets the average scores for each quiz.
void get_course_avg(const int grade[][number_quizzes], double test_avg[]);
//this gets the average score of the course.
//void display(const int grade[][number_quizzes], const int ind_avg[], const int test_avg[], const int course_avg[]);
//displays the grades for the individual,test, and the course.

int main()
{

    int grade[students][number_quizzes];
    double student_avg[students];
    double quiz_avg[number_quizzes];
    double course_avg[number_quizzes];

    ind_avg(grade, student_avg);
    test_avg(grade,quiz_avg);
    get_course_avg(grade,course_avg);

}

void ind_avg(const int grade[][number_quizzes], double student_avg[])
{
    for(int student_num=1; student_num <= students; student_num++)
    {
        double sum=0;
        for(int quiz_num=1; quiz_num <=number_quizzes; quiz_num++)
            sum = sum+grade[student_num-1][quiz_num-1];
        student_avg[student_num-1]=sum/number_quizzes;
    }
}

void test_avg(const int grade[][number_quizzes], double quiz_avg[])
{
    for(int quiz_num =1; quiz_num<= number_quizzes; quiz_num++)
    {
        double sum = 0;
        for(int student_num=1; student_num<= students; student_num++)
            sum = sum+grade[student_num-1][quiz_num-1];
        quiz_avg[quiz_num-1] = sum/students;
    }
}

void get_course_avg(const int grade[][number_quizzes], double test_avg[])
{
    for(int course_num = 1; course_num<= number_quizzes; course_num++)
    {
        int sum = 0;
        for(int quiz_avg=1; student_num < number_quizzes;student_num++)
            sum = sum +grade[student_num-1][quiz_num-1];
        course_avg[test_avg-1]= sum/number_quizzes;
    }
}
Last edited on
The first two are simply, describing the error exactly. You are using those two variables without having declared them.

The third is probably regarding line 64. You are taking the array test_avg, subtracting 1 from it (...??), then trying to use it to index into a different array (???). What were you expecting that to do?
Topic archived. No new replies allowed.