I am trying to make a program where a user enters elements to 2 arrays, and it checks which elements are the same:
#include <iostream>
using namespace std;
int main()
{
int firstarray[5] = {0, 0, 0, 0, 0};
int secondarray[5] = {0, 0, 0, 0, 0};
cout << "enter 5 numbers seperated by a space e.g 3 4 5 6 7: ";
cin >> firstarray[0] >> firstarray[1] >> firstarray[2] >> firstarray[3] >> firstarray[4];
cout << "enter another 5 numbers seperated by a space: ";
cin >> secondarray[0] >> secondarray[1] >> secondarray[2] >> secondarray[3] >> secondarray[4];
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
{
if(firstarray[i] == secondarray[j])
{
cout << "the " << i << " element of both arrays are the same" << endl;
continue;
}
else
{
cout << "the " << i << " element of both arrays are not same" << endl;
continue;
}
}
return 0;
}
when i run it and it i get this output:
enter 5 numbers seperated by a space e.g 3 4 5 6 7: 1 1 1 1 1
enter another 5 numbers seperated by a space: 1 1 1 1 1
the 0 element of both arrays are the same
the 0 element of both arrays are the same
the 0 element of both arrays are the same
the 0 element of both arrays are the same
the 0 element of both arrays are the same
the 1 element of both arrays are the same
the 1 element of both arrays are the same
the 1 element of both arrays are the same
the 1 element of both arrays are the same
the 1 element of both arrays are the same
the 2 element of both arrays are the same
the 2 element of both arrays are the same
the 2 element of both arrays are the same
the 2 element of both arrays are the same
the 2 element of both arrays are the same
the 3 element of both arrays are the same
the 3 element of both arrays are the same
the 3 element of both arrays are the same
the 3 element of both arrays are the same
the 3 element of both arrays are the same
the 4 element of both arrays are the same
the 4 element of both arrays are the same
the 4 element of both arrays are the same
the 4 element of both arrays are the same
the 4 element of both arrays are the same
However what I am only trying to print one line saying the element is the same, but it prints it 5 times. Is there a way I can print the line only 1 time?
What I have tried:
I have tried to write different code but it still doesnt work