Keep getting this error "error: expected primary-expression before ‘int’"

Hi guys so I'm coding up a little assignment for class, and I keep getting the error mentioned, so I thought I'd come and ask for help over here.

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
/*
   Trying to write a function, Even, that will tell you the total amount of even numbers in the array
*/

#include <iostream>
using namespace std;

const int MAX_ROWS = 3;
const int MAX_COLUMNS = 2;

int Even(int A[int length][int width], int length, int width)
{
    int evenCounter = 0;
    for (int i = 0; i < length; i++)
    {
        for (int j = 0; j < width; j++)
        {
            if(A[i][j] % 2 == 0)
            {
                evenCounter++;
            } // end if
            else
            {

            } // end else
        } // end inner for loop
    } // end outer for loop
    return evenCounter;
} //end function Even

int main()
{
    int A[MAX_ROWS][MAX_COLUMNS] = {{3,2},{4,5},{2,2}};
    cout << Even(A,MAX_ROWS,MAX_COLUMNS) << endl;
}
you are declaring your array incorrectly I think. I am not 100% sure. Here is some code I whipped up after doing a bit google searching. '


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
#define numRows 3
#define numCols 7
#define TotalNum (numRows*numCols)

using namespace std; 
int arr[numRows][numCols] = {{0,1,2,3,4,5,6}, {7,8,9,10,11,12,13},{14,15,16,17,18,19,20}};


bool isOdd( int integer )
{

    if ( integer % 2== 0 )
        return true;
    else
        return false;
}

void display(int p[][numCols])
{
    printf("\n");
    for (int i = 0; i< numRows;i++)
    {
        for ( int j = 0;j< numCols;j++)
        {
            if(isOdd(p[i][j]) == false)
                cout << p[i][j] << " is odd." << endl;
            else
                cout << p[i][j] << " is even." << endl;
        }
        printf("\n");
    }
}



int main() {
    display(arr);
}

EDIT
Meant to say declaring your array prototype incorrectly.
and passing array incorrectly.
Last edited on
Topic archived. No new replies allowed.