Primary-Expression Compilation Error

I tried compiling this code, and the error that says that the Array parameter in the function requires something called a primary-expression.

What is it and how can 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
using namespace std;

const int ROWCAP = 100;
const int COLCAP = 100;

// Function Prototypes
int findNorm(int userMatrix[ROWCAP][COLCAP], int, int);

int main()
{
    // Initialize Variables
    int rows;
    int cols;

    // Initialize Matrix
    int userMatrix[ROWCAP][COLCAP];

    cout << "We will find the 1 Norm (Maximum Absolute Sum Norm) of your matrix.\n";

    // Enter Amount of Rows
    cout << "Please enter the amount of rows (MAX of 100).\n";
    cout << "> ";
    cin >> rows;

    // Validate Amount of Rows
    while (rows <= 0 || rows >= ROWCAP)
    {
        cout << "Please enter a row size that is between 0 and 100.\n";
        cout << "> ";
        cin >> rows;
    }

    // Enter Amount of Columns
    cout << "Please enter the amount of columns (MAX of 100).\n";
    cout << "> ";
    cin >> cols;

    // Validate Amount of Columns
    while (cols <= 0 || cols >= COLCAP)
    {
        cout << "Please enter a row size that is between 0 and 100.\n";
        cout << "> ";
        cin >> cols;
    }

    // Enter Matrix Values
    cout << "Enter your Matrix.\n";
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            cout << "> ";
            cin >> userMatrix[i][j];
        }
    }

    // Display the User Matrix
    cout << "Your Matrix is:\n";
    for (int k = 0; k < rows; k++)
    {
        for (int l = 0; l < cols; l++)
        {
            cout << userMatrix[k][l];
        }
    }

    // Find and Display the 1 Norm
    cout << "The Absolute Maximum Sum Norm is: " << findNorm(int userMatrix[ROWCAP][COLCAP], rows, cols) << ".\n";

    return 0;
}

// 1 Norm Function
int findNorm(int userMatrix[ROWCAP][COLCAP], int rows, int cols)
{
    int sum;
    int largest;
    int total[cols];

    cout << "\nCalculating Absolute Maximum Column Sum...\n";

    // Column Calculation
    for (int m = 0; m < rows; m++)
    {
        for (int n = 0; n < cols; n++)
        {
            sum += userMatrix[m][n];

            for (int o = 0; o < cols; o++)
            {
                sum = total[o];
            }
        }
    }

    largest = total[0];
    for (int p = 1; p < cols; p++)
    {
        if (largest < total[p])
        {
            largest = total[p];
        }
    }

    cout << "Done!\n";

    return largest;
}
Just
cout << "The Absolute Maximum Sum Norm is: " << findNorm(userMatrix, rows, cols) << ".\n";

Don't try to redefine the array - just pass it as an argument (by giving its name only).
Lets see:
 In function 'int main()':
69:62: error: expected primary-expression before 'int'

Which occurs in:
1
2
3
4
// Find and Display the 1 Norm
cout << "The Absolute Maximum Sum Norm is: "
     << findNorm(int userMatrix[ROWCAP][COLCAP], rows, cols) // error
     << ".\n";

I presume you are trying to call a function.

Looking "Arrays as parameters" in http://www.cplusplus.com/doc/tutorial/arrays/
shows:
1
2
3
4
5
6
7
8
9
void printarray( int arg[], int length );

int main ()
{
  int firstarray[] = {5, 10, 15};
  printarray( firstarray, 3 );

  // not: printarray( int firstarray[], 3 );
}


Topic archived. No new replies allowed.