Finding if two matrices are identical

I am having some trouble with my current code. It seems to always return false when the only time it should be doing this is if he numbers in the same location of the two matrices are different.

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
  #include <iostream>
using namespace std;
const int SIZE = 3;
bool equals(const int m1[][SIZE], const int m2[][SIZE])
{
    bool identical = true;
    for (int i=0; i < SIZE && identical; i++ ){
        for(int x = 0; x < SIZE; x++){
    
        if (m1[i][x] != m2[i][x]){
            identical = false;
        }
    }
    }
    return identical;
}


int main(){
  int m1[][SIZE] = {};
  int m2[][SIZE] = {};
  
  cout << "Please enter the first 2D (3x3) matrix" << endl;
  
  for(int x = 0; x < SIZE; x++){
    for(int y = 0; y < SIZE; y++){
        cin >> m1[x][y];   
    }
  }
  
  cout << "Please enter the second 2D (3x3) matrix" << endl;
  
  for(int x = 0; x < SIZE; x++){
    for(int y = 0; y < SIZE; y++){
        cin >> m2[x][y];   
    }
  }
  
  if(equals(m1, m2)){
   cout << "The two matrices are the same" << endl;   
  } else{
    cout << "The two matrices are different" << endl;   
  }
}


For example if I were to enter the matrix:
1 2 3
1 2 3
1 2 3

1 2 3
1 2 3
1 2 3

It say they are not the same, which they clearly are. Did I do something wrong in my equal void statement, or did I fill/create the 2D arrays incorrectly?
When I initialized the arrays and provided both dimensions, the program worked.
20
21
  int m1[SIZE][SIZE] = {};
  int m2[SIZE][SIZE] = {};
Oh I just forgot to initialize the array. Can't believe I overlooked that. Thanks.
Topic archived. No new replies allowed.