title: C++ incrementing a globally declared counter
body: <p>say I had a counter declared globally that incremented in another function</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int count = 0;
  
  string passorFail(int x, int y)
  {
  
      if (x &gt; y)
      {
          return &quot;pass&quot;;
          count++;
      }
      else
      {
          return &quot;fail&quot;;
      }
  }
  
  int main()
  {
  
      int x = 10;
      int y = 5;
  
      passorFail(x, y);
      std::cout &lt;&lt; &quot;Count: &quot; &lt;&lt; count &lt;&lt; std::endl;
  }
  </code></pre>
  <p>However when this runs it just returns 0, where as Id like it to return 1. I know people will say declare within the function but for the purposes of what im doing count has to be global. How can i achieve this?</p>