Please need help fixing the errors in array problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
int sixCount(int arr[][6], int nr,int nc){
        for(int r=0; r<=nr; r++)
        for(int c=0; c<=nc; c++)
        if(arr[r][c] == 6)return 1;
           if(arr[r][c] <10)return 0;
           return sixCount(arr[r][c]/10) + sixCount(arr[r][c]%10);
        }
int main()
{  
        //sixCount:
        //cout << "Testing sixCount: ";
        int arr4 [2][6] = {{6, 4, 3, 1, 2, 2666}, {6, 6, 5, 2, 3, 66}};
        //cout << sixCount (arr4, 2, 6) << endl; //prints: 8, since 6 appears e$
        
        cout << endl;
        
        return 0;
}

lab12.cpp: In function ‘int sixCount(int (*)[6], int, int)’:
lab12.cpp:27: error: name lookup of ‘r’ changed for new ISO ‘for’ scoping
lab12.cpp:24: error:   using obsolete binding at ‘r’
lab12.cpp:27: error: ‘c’ was not declared in this scope
lab12.cpp:28: error: ‘c’ was not declared in this scope


Please need help fixing the above errors
i am trying to get the sixcount in the array, that is i want the program to output the amount of sixes that are in the array... but these errors above hinder my progression
I see at least 3 errors:

1. For Lines 4 and 5 you need braces, or you're going to have problems on Lines 6 and 7.
2. Line 8 looks wrong - are you sure you want to use recursion? If you do, you still need to pass the right number of arguments and make sure you have a terminal case.
3. For Lines 4 and 5, you want <, not <=
if not recursive what other way can i possibly do it?
Iteration, stacks, hashes - google on "replacing recursion" for details.

I am not saying don't use recursion.
I am saying that if you want to use recursion, make sure you know what you are doing.

The fact that your function calls don't even have the right number of arguments is a cause for concern (Line 8).
Topic archived. No new replies allowed.