title: Getting Only Even Numbers in C++
body: <p>I'm currently attempting to go through Project Euler to increase my understanding of C++, but I'm stumped on problem 2 on the part of how to get only even numbers in a Fibonacci sequence. I'm 99% sure that you have to use the % operator just from things I've looked at online, but all I understand of it is that it takes the remainder of something (ex 11/3 = 9 w/ remainder of 2), and so I have no idea on how to incorporate it into the code.</p>
  
  <p>The problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:</p>
  
  <p>1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...</p>
  
  <p>By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.</p>
  
  <pre><code>using namespace std;
  
  int main()
  {
  int first = 1;
  int second = 2;
  int next;
  
  cout &lt;&lt; first &lt;&lt; endl;
  cout &lt;&lt; second &lt;&lt; endl;
  if (next &lt; 4000000)
  {
      for (int i = 0; i &lt; 500000; i++)
      {
          next = first + second;
          first = second;
          second = next;
      }
  }
  
  
  cout &lt;&lt; next &lt;&lt; endl;
  
  return 0;
  }
  </code></pre>