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.
#include <iostream>
usingnamespace std;
constint SIZE = 3;
bool equals(constint m1[][SIZE], constint 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?