title: Keep increasing array size C++
body: <p>I am new to C++ and I am trying to allow the user to keep entering doubles into an array, the program stops when the user enters -1. The code I have works but when 12 items are added to the array I get these errors:</p>
  
  <blockquote>
    <p>*** glibc detected *** ./exercise2: double free or corruption (out): 0x00000000010aa070 ***<br/>
    ======= Backtrace: =========</p>
  </blockquote>
  
  <p>and:</p>
  
  <blockquote>
    <p>Aborted (core dumped)</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>int main(){
      int size=5;
      int i=0;
      double *numbers = new double[size];
      cout&lt;&lt;"Enter your double:"&lt;&lt;endl;
  
      while(1){
      double *numbers2=new double[size];
  
      cin&gt;&gt;numbers[i];
  
      if(i&gt;=size-1){
          size=size*2;
          memcpy(&amp;numbers2, &amp;numbers, size);
          delete[]numbers;
      numbers=numbers2;
      }
  
      if(numbers[i]==-1){
          break;
      }
      cout&lt;&lt;numbers[i];
          i++;
      } 
  }
  </code></pre>