title: Remove an element from a dynamic array
body: <p>for one of my assignments I have to create a class that creates a dynamic array and has methods to add or remove a number from the array, I figured out how to do the add method and it works fine but I cannot figure out how to remove an element and make the size of the array decrease by one.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class IntegerDynamicArray
  {
      public:
          IntegerDynamicArray()
          {
              currentSize = 0;
              maxSize = 10;
              dynamicArray = new int[maxSize];
          }
  
          int add(int x);
          bool remove(int x);
      private:
          int* dynamicArray;
          int currentSize;
          int maxSize;
  };
  
  int IntegerDynamicArray::add(int x)
  {
      if (currentSize == maxSize)
      {
          maxSize = maxSize * 2;
          int* tempArray = new int[maxSize];
          for (int i = 0; i &lt; currentSize; i++)
          {
              tempArray[i] = dynamicArray[i];
          }
          tempArray[currentSize] = x;
          currentSize++;
          dynamicArray = tempArray;
      }
      else
      {
          dynamicArray[currentSize] = x;
          currentSize++;
      }
      return currentSize;
  }
  
  bool IntegerDynamicArray::remove(int x)
  {
      for (int i = 0; i &lt; currentSize; i++)
      {
          if (dynamicArray[i] == x)
          {
              //TODO need to delete the number and move all numbers "back" by one
              return true;
          }
      }
      return false;
  }
  
  int main()
  {
      IntegerDynamicArray intDynArray;
      while (1)
      {
          char input;
          cout &lt;&lt; "Enter A for add or R for remove: ";
          cin &gt;&gt; input;
          if (input == 'A')
          {
              cout &lt;&lt; "Enter number to add: ";
              int x;
              cin &gt;&gt; x;
              cout &lt;&lt; intDynArray.add(x) &lt;&lt; endl;
          }
          else if (input == 'R')
          {
              cout &lt;&lt; "Enter number to remove: ";
              int x;
              cin &gt;&gt; x;
              cout &lt;&lt; intDynArray.remove(x) &lt;&lt; endl;
          }
      }
  }
  </code></pre>