title: Finding middle number in dynamic array C++
body: <p>I am trying to find the middle number in my dynamic array. A user enters three numbers and the program then sorts it from smallest to biggest. It works fine until I enter the numbers 10,20,30 it outputs 10,10,30 and when I input 30,20,10 it outputs 10,30,30.</p>
  
  <p>Here is part of my code.
  Thanks</p>
  
  <pre><code>cout &lt;&lt; "Enter 3 values and I will sort them from lowest to highest." &lt;&lt; endl;
  
  for (index = 0; index &lt; 3; index++)
  {
      cin &gt;&gt; number[index];
  
      while (cin.fail())//Check that values entered are the correct type.
      {
          cout &lt;&lt; "You did not enter a number" &lt;&lt; endl;
          cout &lt;&lt; "Enter a new number." &lt;&lt; endl;
          cin.clear();//Clears the input if user input non-integer value.
          cin.ignore(1000, '\n');//Ignores up to 1000 characters or up to new line.
  
          cin &gt;&gt; number[index];
      }//end while
  }//end for
  
  cout &lt;&lt; "You have entered the values" &lt;&lt; endl;
  for (index = 0; index &lt; 3; index++)
  {
      cout &lt;&lt; number[index] &lt;&lt; " ";
      cout &lt;&lt; endl;
  }//end for
  
  small = number[0];
  mid = number[0];
  high = number[0];
  
  for (int i = 0; i &lt; 3; i++)//Goes through the array to determine order of values.
  {
      if (small &gt; number[i])
      {
          small = number[i];
      }
      else if (high &lt; number[i])
      {
          high = number[i];
      }
      else if (high &gt; mid &amp;&amp; mid &gt; small)
      {
          mid = number[i];
      }
  
  }
  
  cout &lt;&lt; "Here is the new order of your numbers." &lt;&lt; endl;
  cout &lt;&lt; small &lt;&lt; endl;
  cout &lt;&lt; mid &lt;&lt; endl;
  cout &lt;&lt; high &lt;&lt; endl;
  </code></pre>