title: Binary Search using a vector
body: <p>So.. Ive already learnt of Binary Search and how it works and even tried it using a constant array without any input from the user , But now im trying to apply vector instead of array to have the user enter the values of both the list in which to search the numbers from <strong>vector</strong> and the target to search for. Here i used a normal divide&amp;conquer while using an array </p>
  
  <pre><code>using namespace std;
  int Binary_search(int x[],int size,int target){
      int maximum= size-1;
      int minimum = 0;
      int mean;
      while (maximum&gt;minimum){
          mean = (maximum+minimum)/2;
          if (x[mean] == target){
              cout &lt;&lt; "The number you're looking for is found! \n";
              return mean;
          }
          else if(x[mean] &gt; target){
              maximum = (mean-1);
          }
          else{
              minimum = (mean+1);
          }
      }
      return -1;
  }
  int main(){
      int x[]={1,2,3,4,5};
      int a=sizeof(x)/sizeof(x[0]);
      int target=4;
      int show=Binary_search(x,a,target);
      if (show != -1){
          cout &lt;&lt; "Your result is in the index: " &lt;&lt; show;
      }
      return 0;
  }
  </code></pre>
  
  <p>My problem is that I made pretty much the same method using vector instead but it's showing either an infinite amount of **Your result is found at the index: ** (number of wrong index) . Or it doesnt show any result at all or even show that the result is not found , Differs each time somehow. Here's while using the vector </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  int Binary_search(vector&lt;int&gt;x,int target){
      int maximum=(x.size())-1;
      int minimum = 0;
      int mean;
      while (maximum&gt;minimum){
          mean = (maximum+minimum)/2;
          if (x[mean] == target){
              cout &lt;&lt; "The number you're looking for is found! \n";
          }
          else if(x[mean] &gt; target){
              maximum = (mean-1);
          }
          else{
              minimum = (mean+1);
          }
      }
      return -1;
  }
  int main(){
      unsigned int i;
      int n;
      vector&lt;int&gt;x;
      cout &lt;&lt; "Enter the amount of numbers you want to evaluate: ";
      cin &gt;&gt; i;
      cout &lt;&lt; "Enter your numbers to be evaluated: " &lt;&lt; endl;
      while (x.size() &lt; i &amp;&amp; cin &gt;&gt; n){
          x.push_back(n);
      }
      int target;
      cout &lt;&lt; "Enter the target you want to search for in the selected array \n";
      cin &gt;&gt; target;
      int show = Binary_search(x,target);
      if (show == -1){
          cout &lt;&lt; "Your result is not found ! ";
      }
      else{
          cout &lt;&lt; "Your result is in the index: " &lt;&lt; show;
      }
      return 0;
  }
  </code></pre>
  
  <p>So I think the problem is in this part <code>int maximum=(x.size())-1;</code> , Maybe it's about how to use the size of vectors ? Could someone enlighten me up to this </p>