title: Unknown error in code
body: <p>Here's a link to the problem I am trying to solve: <a href="http://usaco.org/index.php?page=viewproblem2&amp;cpid=187" rel="nofollow">http://usaco.org/index.php?page=viewproblem2&amp;cpid=187</a></p>
  
  <p>Here's a link to the solution of the problem: <a href="http://usaco.org/current/data/sol_cowfind.html" rel="nofollow">http://usaco.org/current/data/sol_cowfind.html</a></p>
  
  <p>Here's my solution that I wrote:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
      string n; int answer = 0;
      ifstream fin("cowfind.in");
      fin &gt;&gt; n;
      fin.close();
      int c = 0;
  
      //process for finding the number of possible outputs
      for(int i = 0; i &lt; n.size(); i++)
      {
          if(n[i-1] == '(' &amp;&amp; n[i] == '(') //increment the variable c for each pair of "hind" legs
              c++;
          if(n[i-1] == ')' &amp;&amp; n[i] == ')') //increment answer for each pair of front legs
              answer++;
      }
      answer = answer * c; //number of pairs of hind legs * number of pairs of front legs
      ofstream fout("cowfind.out");
      fout &lt;&lt; answer;
      fout.close();
      return 0;
  }
  </code></pre>
  
  <p>With that being said, what is wrong with my code? It keeps producing incorrect outputs, and I'm not sure why. </p>