Attempting to pass by reference

Attempting to pass by reference and I'm getting these errors.
1
2
3
4
5
6
7
8
main.cpp:30:29: error: declaration of 'counts' as array of references
 void digitCount(int &counts[], char &digitsArr[])
                             ^
main.cpp:30:30: error: expected ')' before ',' token
 void digitCount(int &counts[], char &digitsArr[])
                              ^
main.cpp:30:32: error: expected unqualified-id before 'char'
 void digitCount(int &counts[], char &digitsArr[])


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

using namespace std;
const int SIZE = 12;
const int NUM_DIGITS = 10;
void printCounts(int []);
void digitCount (char[], int[]);

int main()
{
    char digitsArr[SIZE]={'3','0','8','1','9','4','2','6','7','5','2','2'};
   char oneDigit; //one digit
   
    int countDigits[NUM_DIGITS] = {0};
    
   printCounts(countDigits);
   
    
}

void printCounts(int counts[])
{
    cout << "\nCounts are: "<< endl;
    
    for(int i =0; i<NUM_DIGITS;i++) {
        cout << "Digit " <<  i << " occurs " << counts[i] << " time(s)." << endl;
    }
}

void digitCount(int &countDigits[], char &digitsArr[])
{
  
   for(int i=0;i<SIZE;i++) {
        oneDigit = digitsArr[i];
        
        if (oneDigit =='0')
           countDigits[0]++;
        else if (oneDigit =='1')
           countDigits[1]++;
        else if (oneDigit =='2')
           countDigits[2]++;
        else if (oneDigit =='3')
           countDigits[3]++;
        else if (oneDigit =='4')
           countDigits[4]++;
        else if (oneDigit =='5')
           countDigits[5]++;
        else if (oneDigit =='6')
           countDigits[6]++;
        else if (oneDigit =='7')
           countDigits[7]++;
        else if (oneDigit =='8')
           countDigits[8]++;
        else if (oneDigit =='9')
           countDigits[9]++;
        else 
           ; //to be completed 
    }
}
Last edited on
Okay so It looks like I am trying to reference a reference, but I'm not sure how to fix that.
Topic archived. No new replies allowed.