invalid types, int[int]

Could someone explain why on line 45 I am getting the error "invalid types int[int] for array subscripts"?

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

using namespace std;

int i = 0;
int testArray[100] = {0};
bool loopFlag = true;
int numbers(int[], int&);

int main()
{

    char command;

    cout << "Welcome to Stats Array!" << endl;
    cout << "These are your choices:" << endl;
    cout << "N - Numbers" << endl;
    cout << "S - Sum of all" << endl;
    cout << "A - Average of all" << endl;
    cout << "B - Biggest of all" << endl;
    cout << "F - Most Frequent of all" << endl;
    cout << "H - How many numbers" << endl;
    cout << "M - Median of all" << endl;
    cout << "Q - Quit" << endl;

    do
    {
    cin >> command;
    switch(command)
    {


        case 'N':
        numbers(testArray, i);
    }

    }while(loopFlag);


    return 0;
}

numbers(int testArray, int& i)
{
    cin >> testArray[i];
    i++;

}
Because testArray has been declared as an int inside the numbers function. An int doesn't have a subscript operator so that is why you get that error.
Topic archived. No new replies allowed.