title: Sieve of Eratosthenes algorithm
body: <p>I am currently reading <em>"Programming: Principles and Practice Using C++"</em>, in <em>Chapter 4</em> there is an exercise in which:</p>
  
  <blockquote>
    <p>I need to make a program to calculate prime numbers between 1 and 100 using the Sieve of Eratosthenes algorithm.</p>
  </blockquote>
  
  <p>This is the program I came up with:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  //finds prime numbers using Sieve of Eratosthenes algorithm
  vector&lt;int&gt; calc_primes(const int max);
  
  int main()
  {
      const int max = 100;
  
      vector&lt;int&gt; primes = calc_primes(max);
  
      for(int i = 0; i &lt; primes.size(); i++)
      {
          if(primes[i] != 0)
              cout&lt;&lt;primes[i]&lt;&lt;endl;
      }
  
      return 0;
  }
  
  vector&lt;int&gt; calc_primes(const int max)
  {
      vector&lt;int&gt; primes;
  
      for(int i = 2; i &lt; max; i++)
      {
          primes.push_back(i);
      }
  
      for(int i = 0; i &lt; primes.size(); i++)
      {
          if(!(primes[i] % 2) &amp;&amp; primes[i] != 2)
               primes[i] = 0;
          else if(!(primes[i] % 3) &amp;&amp; primes[i] != 3)
               primes[i]= 0;
          else if(!(primes[i] % 5) &amp;&amp; primes[i] != 5)
               primes[i]= 0;
          else if(!(primes[i] % 7) &amp;&amp; primes[i] != 7)
               primes[i]= 0;
      }   
  
      return primes;
  }
  </code></pre>
  
  <p>Not the best or fastest, but I am still early in the book and don't know much about C++.</p>
  
  <p>Now the problem, until <code>max</code> is not bigger than <code>500</code> all the values print on the console, if <code>max &gt; 500</code> not everything gets printed.</p>
  
  <p>Am I doing something wrong?</p>
  
  <p>P.S.: Also any constructive criticism would be greatly appreciated.</p>