Comparing each element in two different arrays

I am trying to work on this problem where I have to compare two arrays, and print out 'equal' or 'not equal' for each element in both arrays that is/are equal or not equal. So for this, I have 2 integers that are equal and 2 that are not equal. So it has to print out: not equal, equal, not equal, and equal. Thanks!

#include <iostream>
using namespace std;

int main() {
int firstArray[4] = {5, 15, 25,30};
int secondArray[4] = {2, 15, 20, 30};

for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
if(firstArray[i] == secondArray[j]) {
cout << "equal" << endl;
} else
cout << "not equal" << endl;
return 0;
}
}
}
You don't need a double loop (that's for a two-dimensional array).
Get rid of the j loop and use i to index both arrays.
Ok Thank you. But I'm still trying to figure out how I can print out 'equal' or 'not equal' for comparing each element in the array?
Why don't you actually try doing what I suggested and see if that fixes your problem?
I actually did that. Thank you. But its not printing the equal or not equal for each element. Thanks for your help.
Get rid of the "return 0" (you don't need it in main) or at least put it at the very end, before the closing brace.
Right now, it's inside the loop so your program quits at the end of the first iteration.
Awesome. Thanks so much for your help!
Topic archived. No new replies allowed.