title: Inserting a random number into an array with sorted order C++
body: <p>Hello I am trying to make an array that inserts a random number but when it does, the array stays in a maintained order. For example if the array contained 10 20 30 and the random number was 11 the function would put it after 10 and move 20 and 30 down the list. Here are the requirements for the function. </p>
  
  <ul>
  <li>insertNumber inserts a  given random number into the array and maintains order.</li>
  <li>The data array contains integers in sorted order from index 0 through size - 2.</li>
  <li>randomNum is the integer to be inserted</li>
  <li>data is the array containing sorted integers</li>
  <li>size is the total number of elements which the array can hold</li>
  </ul>
  
  <p>Here is my code so far. I am getting nothing in my output. </p>
  
  <pre><code>#include"utils.h" 
  
  void insertNumber(int randomNum, int data[], int size)
  {
      for(int i = 0; i &lt; 10; i++)
      {
          randomNum = data[i];
          if (randomNum &gt; data[i] &amp;&amp; i &lt; size - 2)
          {
              for ( int j = 0; j &lt; 10; j--)
              {
                  data[i+1] = data [i];
                  i--;
              } 
          }
          data[i] = randomNum;
      }
  }
  
  void display(int data[],  int size)
  {
      for (int i = 0; size &lt; 10; i++)
      {
          cout &lt;&lt; " " &lt;&lt; data[i];
      }
  
  }
  </code></pre>