Problem with calculating Primes within a given Range in C++ : <p>Im trying to create a program that does various math operations, and i wanted to start with calculating prime numbers within a given range. However, when i try to execute the code, it just returns <code>exit status -1</code>. What is wrong with the program and how do i fix it?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

void getPrimes(int min, int max) {

  int range = max - min;

  std::vector&lt; int &gt; possible_values;

  for (int q = 0; q &lt; range; q++) {

    possible_values.push_back(min + q);

  }

  for (int i = 0; i &lt; range; i++) { 

    int num_of_factors = 0;
    int num = possible_values.at(i);

    for (int c = 0; c &lt; num; c++) {
      if (num % c == 0) {
        num_of_factors++;
      }
    }

    if (num_of_factors == 0) {
      std::cout &lt;&lt; num &lt;&lt; endl;
    }
  }
}

int main() {

  int min, max;

  std::cout &lt;&lt; "min: ";
  std::cin &gt;&gt; min;

  std::cout &lt;&lt; "max: ";
  std::cin &gt;&gt; max;

  getPrimes(min, max);
}
</code></pre>
