1 Replies - 2935 Views - Last Post: 24 November 2011 - 08:43 AM

#1 nquadr  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 120
  • Joined: 30-October 10

Problems with a multidimensional array

Posted 24 November 2011 - 01:00 AM


I am having problems with compiling this code for a multidimensional array. Any help would be appreciated.

#include <cstdlib>
#include <iostream>

using namespace std;

void det2(int[][]);

int main()
    int rows = 2;
    int cols = 2;
    int i, j, matrix[rows][cols];
    for(i=0; i<rows; i++)
        cout<<"Enter a Value :";
        for(j=0; j<cols; j++)
        cin >> matrix[i][j];
    for(i=0; i<rows; i++)
        for(j=0; j<cols; j++)
        cout<< "Values are " << i << "" << j << " is " << matrix[i][j] << endl;
    return 0;

void det2(matrix)
        int x = matrix[0][0]* matrix[1][1] - matrix[1][0]* matrix[0][1];

I am new to arrays so I am not sure what I am doing wrong but here are the error codes:

main.cpp:7: error: multidimensional array must have bounds for all dimensions except the first

main.cpp: In function `int main()':
main.cpp:7: error: too many arguments to function `void det2()'
main.cpp:26: error: at this point in file

main.cpp: At global scope:
main.cpp:31: error: variable or field `det2' declared void
main.cpp:31: error: `int det2' redeclared as different kind of symbol
main.cpp:7: error: previous declaration of `void det2()'
main.cpp:31: error: declaration of `int det2'
main.cpp:7: error: conflicts with previous declaration `void det2()'
main.cpp:31: error: `matrix' was not declared in this scope
main.cpp:32: error: expected `,' or `;' before '{' token

mingw32-make.exe: *** [Objects/MingW/main.o] Error 1

Execution terminated
Compilation Failed. Make returned 2

Is This A Good Question/Topic? 0
  • +

Replies To: Problems with a multidimensional array

#2 jimblumberg  Icon User is offline

  • member icon

Reputation: 5466
  • View blog
  • Posts: 17,017
  • Joined: 25-December 09

Re: Problems with a multidimensional array

Posted 24 November 2011 - 08:43 AM

You must tell the compiler the size of all but the first array dimension. Ie:void det2(int[][2]);. Also your function prototype, function call, and function implementation must all agree on the number and type of parameters. You may want to study the links in my signature for more information.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1