title: Checking two arrays for similar elements, returns correct values for some tests, incorrect for others
body: <p>I have a function which intends to see if two arrays contain similar elements.</p>
  
  <p>This is the main function:</p>
  
  <pre><code>int arr[] = {1, 2, 2};
  int arrb[] = {1, 2, 1};
  int a = (sizeof(arr)/sizeof(arr[0]));
  int b = (sizeof(arrb)/sizeof(arrb[0]));
  cout &lt;&lt; checkForSimilar(arr,arrb,a,b);
  </code></pre>
  
  <p>and the following function:</p>
  
  <pre><code>int checkForSimilar(int arraya[], int arrayb[], int a, int b)
  {
      if (a != b) return 0; else
      {
          int foundSwitch = 0;
          int found = 0;
          for (int i = 0; i &lt; a; i++)
          {
              for (int j = 0; j &lt; b; j++)
              {
                  if (arraya[i] == arrayb[j])
                  {
                      foundSwitch = 1;
                      break;
                  } else foundSwitch = 0;
              }
          }
          return foundSwitch;
      }
  }
  </code></pre>
  
  <p>The function is not returning expected values, however. In the above example, for example, it should return 0, but it returns 1. This function returns the correct value for some arrays and not the correct one for others. I don't understand what I am doing wrong here.</p>
  
  <p><strong>EDIT:</strong> I worded the above function poorly. It's an equality test, where both arrays need to contain the same elements. However, they don't have to be in the same order.</p>