title: Problems with adding prime numbers in C++
body: <p>My code works for numbers up to 300 or 20. But it doesn't work for 2000000. I tried using long instead, but it still didn't work.</p>
  
  <pre><code>#include &lt;iostream&gt;
  bool prime(int i) {
      bool result = true;
      int isitprime = i;
  
      for (int j = 2; j &lt; isitprime; j++) { ///prime number tester
          if (isitprime % j == 0) {
              result = false;
              break;
          }
      }
  
      return result;
  }
  
  int main(void) {
      using namespace std;
      long sum = 0;
  
      for (long i = 2; i &lt;= 2000000; i++) {
          if (prime(i)) {
              sum += i;
          }
      }
  
      cout &lt;&lt; sum &lt;&lt; endl;
      system("pause");
      return 0;
  }
  </code></pre>