title: I am trying to find the height of a Binary tree with this code, but it keeps returning 0, can someone tell me why?
body: <p>I am trying to find the height of a Binary tree with this code, but it keeps returning 0, can someone please tell me why?</p>
  
  <pre><code>int heightHelper(Node* root, int maxheight, int rootheight)
  {
  
      if (root-&gt;right == nullptr &amp;&amp; root-&gt;left == nullptr) { //checks if the node has a child
          if (maxheight &lt; rootheight) {
              maxheight = rootheight;
          }
      }
      else { //if it has then increase height by 1
          rootheight += 1;
  
          if (root-&gt;left != nullptr) {
              heightHelper(root-&gt;left, maxheight, rootheight);
          }
          if (root-&gt;right != nullptr) {
              heightHelper(root-&gt;right, maxheight, rootheight);
          }
      }
  
      return maxheight; //return height
  }
  
  int height(Node* root)
  {
      // Write your code here.
  
      return heightHelper(root, 0, 0); //root node base case
  }
  </code></pre>