title: Logic errors with search
body: <p>I finished my code recently, but my output for my bubbleSort function is wrong.
  I missed the first two elements. </p>
  
  <p>I've tried to change it around a bit, but still no success. </p>
  
  <p>NUM_FOR_CAL1</p>
  
  <p>NUM_FOR_CAL2 </p>
  
  <p>Seem to be my problems.</p>
  
  <p>Anyone have any ideas on how to fix this logic error? </p>
  
  <pre><code> //Searching Benchmarks exercise
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  
  //module prototypes
  int binarySearch(int t, int arr[], int n);
  int bubbleSort(int num[], int n);
  void printArray(int arr[], int SIZE);
  
  
  //global constants
  const int SIZE=20;
  const int NUM_FOR_CAL1=1;
  const int NUM_FOR_CAL2=2;
  const int ZERO_FOR_CAL=0;
  
  int main()
  {
      //some variables
     int swap;
     int arr[SIZE] = {26, 45, 56, 12, 78, 74, 39, 22, 5, 90, 87, 32, 28, 11, 93, 62, 79, 53, 22, 51};
  
     //Showing original order, bubble sort, and the number of swaps
     cout &lt;&lt; "Original Order : ";
     printArray(arr, SIZE);
     swap = bubbleSort(arr, SIZE);
     cout &lt;&lt; "Bubble Sorted : ";
     printArray(arr, SIZE);
     cout &lt;&lt; "Number of location swaps: " &lt;&lt; swap &lt;&lt; endl;
     int num, pos, total = ZERO_FOR_CAL;
     char YesNo;
     do
     {
        cout &lt;&lt; "Select a number in the Array to search for: ";
        cin &gt;&gt; num;
        pos = binarySearch(num, arr, SIZE);
        cout &lt;&lt; "Sequential Search comparisons: " &lt;&lt; pos + NUM_FOR_CAL1&lt;&lt; endl;
        cout &lt;&lt; "The position of the number is " &lt;&lt; pos + NUM_FOR_CAL1 &lt;&lt; endl;
        if(pos != -NUM_FOR_CAL1) total++;
        cout &lt;&lt; "Binary Search comparisons: " &lt;&lt; total &lt;&lt; endl;
        cout &lt;&lt; "The position of the number is " &lt;&lt; pos + NUM_FOR_CAL1 &lt;&lt; endl;
        cout &lt;&lt; "Do you want to search again (Y = Yes) : ";
        YesNo = NUM_FOR_CAL2;
        cin &gt;&gt; YesNo;
     }//end of do while loop to search for array and display comparisons
      while(YesNo == 'Y' || YesNo == 'y');
  
     system("Pause");
     return 0;
  }//end main
  
  //searching array using binarySearch
  int binarySearch(int t, int arr[], int n)
  
  {
     for(int i = ZERO_FOR_CAL; i &lt; n; ++i)
       if(arr[i] == t) return i;
     return -NUM_FOR_CAL1;
  }//end of binarySearch
  
  //searching array using bubbleSort
  int bubbleSort(int num[], int n)
  {
  int i, j, flag = NUM_FOR_CAL1;
  int temp, swap = ZERO_FOR_CAL;
  
  for(i = NUM_FOR_CAL1; (i &lt;= n) &amp;&amp; flag; i++)
  {
      flag = NUM_FOR_CAL2;
      for (j = NUM_FOR_CAL2; j &lt; (n-NUM_FOR_CAL1); j++)
      {
          if (num[j+NUM_FOR_CAL1] &lt; num[j])
          {
              temp = num[j];
              num[j] = num[j+NUM_FOR_CAL1];
              num[j+NUM_FOR_CAL1] = temp;
              flag = NUM_FOR_CAL1;
              swap++;
          }//end of if statement
      }//end of for loop
  }//end of for loop
  return swap;
  }//end bubbleSort
  
  void printArray(int arr[], int SIZE)
  {
  
     for(int i = 0; i &lt; SIZE; i++)
     {
        cout &lt;&lt; arr[i];
        if(i &lt; SIZE - 1) cout &lt;&lt; ", ";
     }
     cout &lt;&lt; endl;
  }
  </code></pre>