title: C++ Array input not accepting certain number of integers
body: <p>I am tasked to create a problem that finds two of the closest numbers from an input of 10, 100, and 1000 random integers. Yes this is for school, data structure and algorithm analysis, but even in my second level c++ course I just had to code "every day" programs and not these "mathematical" questions. I am to the point where I can no longer understand what is going on.</p>
  
  <p>The program works by asking how many elements are you wanting to insert. 
  So enter "10".
  Then enter 10 random elements. Done it works fine.</p>
  
  <p>Now when I go to enter 1000 elements it does nothing. or if I increase the random number say any number could be 1-500, it does nothing.</p>
  
  <p>What is causing this program to accept some input and not other input?</p>
  
  <p>I would really appreciate any pointers, hints, or anything, I'm having a hard time in this course and it's the first week.</p>
  
  <pre><code>#include iostream
  #include vector
  #include chrono
  
  using namespace std;
  using namespace std::chrono;
  
  vector &lt;pair&lt;double, double&gt;&gt; ans;
  double *arr = new double [1200000];
  
  int main()
  {
      int elements;
  
      cout &lt;&lt; "Enter number of array elements: ";
      cin &gt;&gt; elements;
  
      cout &lt;&lt; "Enter the elements: " &lt;&lt; endl;
  
      for (int i = 0; i &lt; elements; i++)
          cin &gt;&gt; arr[i];
  
      auto start = high_resolution_clock::now();
  
      //    Sort the array
      sort(arr, arr + elements);
  
      int smallest = INT_MAX;
  
      for (int i = 1; i &lt; elements; i++)
      {
          if ((arr[i] - arr[i - 1]) &lt;= smallest)
          {
              if ((arr[i] - arr[i - 1] ) &lt; smallest)
                  ans.clear();
  
              smallest = arr[i] - arr[i - 1];
              ans.push_back({arr[i - 1], arr[i]});
           }
       }
  
      auto stop = high_resolution_clock::now();
  
      cout &lt;&lt; "\n\n******* The closest Pair(s) *******" &lt;&lt; endl;
      for(int i = 0; i &lt; ans.size(); i++)
      {
          cout &lt;&lt; "      \t\t" &lt;&lt; ans[i].first &lt;&lt; "\t " &lt;&lt; ans[i].second &lt;&lt; endl;
      }
  
      auto duration = duration_cast&lt;microseconds&gt;(stop - start);
  
      cout &lt;&lt; "Time taken by the function: "
           &lt;&lt; duration.count() &lt;&lt; " microseconds" &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>