title: Sorting two arrays into a combined array
body: <p>I haven't done any programming classes for a few years, so please forgive any beginner mistakes/methods of doing something. I'd love suggestions for the future. With the code below, I'm trying to check the values of two arrays (sorted already) and put them into a combined array. My solution, however inefficient/sloppy, is to use a for loop to compare the contents of each array's index at j, then assign the lower value to index i of the combinedArray and the higher value to index i+1. I increment i by 2 to avoid overwriting the previous loop's indexes. </p>
  
  <pre><code>int sortedArray1 [5] = {11, 33, 55, 77, 99};
  int sortedArray2 [5] = {22, 44, 66, 88, 00};
  combinedSize = 10;
  int *combinedArray;
  combinedArray = new int[combinedSize];
      for(int i = 0; i &lt;= combinedSize; i+=2)
  {
      for(int j = 0; j &lt;= 5; j++)
      {
          if(sortedArray1[j] &lt; sortedArray2[j])
          {
              combinedArray[i] = sortedArray1[j];
              combinedArray[i+1] = sortedArray2[j];
          }
          else if(sortedArray1[j] &gt; sortedArray2[j])
          {
              combinedArray[i] = sortedArray2[j];
              combinedArray[i+1] = sortedArray1[j];
          }
          else if(sortedArray1[j] = sortedArray2[j])
          {
              combinedArray[i] = sortedArray1[j];
              combinedArray[i+1] = sortedArray2[j];
          }
      }
  }
  
  for(int i = 0; i &lt; combinedSize; i++)
  {
      cout &lt;&lt; combinedArray[i];
      cout &lt;&lt; " ";
  }
  </code></pre>
  
  <p>And my result is this</p>
  
  <pre><code>Sorted Array 1 contents: 11 33 55 77 99
  Sorted Array 2 contents: 0 22 44 66 88
  5 77 5 77 5 77 5 77 5 77 Press any key to continue . . .
  </code></pre>
  
  <p>In my inexperienced mind, the implementation of the sorting looks good, so I'm not sure why I'm getting this bad output. Advice would be fantastic.</p>