title: Finding Prime Numbers between Two Numbers
body: <p>Am trying to find all prime numbers between two given numbers and sum the primes up.</p>
  
  <p>I have this loop that does the prime number detection correctly. </p>
  
  <p>However, for some reason I don't know how to sum all the primes.</p>
  
  <pre><code>int a,b,i,j,sum=0;
  
  do
  {   cout &lt;&lt; "Enter a number: ";
      cin &gt;&gt; a;
      if (a &lt; 4 || a &gt; 1000000) 
      {   cout &lt;&lt; "Input must be between 4 and 1000000 inclusive." &lt;&lt; endl;
      }
  }while (a &lt; 4 || a &gt; 1000000);
  
  do
  {   cout &lt;&lt; "Enter a second number: ";
      cin &gt;&gt; b;
      if (b &lt; 4 || b &gt; 1000000) 
      {   cout &lt;&lt; "Input must be between 4 and 1000000 inclusive." &lt;&lt; endl;
      }
  }while (b &lt; 4 || b &gt; 1000000);
  
  if (a &gt; b)
  {   int hold;
      hold = b;
      b = a;
      a = hold;
  }
  
  cout &lt;&lt; "The prime numbers between " &lt;&lt; a &lt;&lt; " and " &lt;&lt; b &lt;&lt; " inclusive are: " &lt;&lt; endl;
  //int sum;
  for (i = a; i &lt;= b; i++)
  {
   for (j = 2; j &lt;= i; j++) // Changed the &lt; to &lt;=, and got rid of semicolon
   {
      if (!(i%j)&amp;&amp;(i!=j)) break;
      if (j==i) 
      {
                cout &lt;&lt; i &lt;&lt; endl;
                sum += i;
                cout &lt;&lt; sum ;
  
      }
   }
  }
  </code></pre>
  
  <p>The variable <code>sum</code> gives me rubbish results. </p>