title: Find average value of binary tree c++
body: <p>So I'm trying to write a recursive function to return the average value of a binary tree of values in c++. Here's what I have, that doesn't work:</p>
  
  <pre><code>double avg(bNode* root)
  {
      if(!root) return 0;
      int sum = avg(root-&gt;left) + avg(root-&gt;right) + root-&gt;value;
      if(root-&gt;left &amp;&amp; root-&gt;right) return sum/3;
      else if(!root-&gt;left &amp;&amp; !root-&gt;right) return sum;
      else return sum/2;
  }
  </code></pre>
  
  <p>Thanks for your help.</p>