title: Finding a String Palindrome with a recursive function
body: <p>I am trying to write a recursive function that will determine if a string is a palindrome. Here is what I have so far:</p>
  
  <pre><code>int main()
  {
      string word = "madam";
  
      if (palindrome(word) == true)
          cout &lt;&lt; "word is a palindrome!" &lt;&lt; endl;
      else
          cout &lt;&lt; "word is not a palindrome..." &lt;&lt; endl;
  
      return 0;
  }
  
  bool palindrome(string word)
  {
      int length = word.length();
  
      string first = word.substr(0,1);
      string last = word.substr((length - 1), 1);
  
      if (first == last)
      {
          word = word.substr((0 + 1), (length - 2));
          cout &lt;&lt; word &lt;&lt; " " &lt;&lt; word.length() &lt;&lt; endl;  // DEBUGGING
          if (word.length() &lt;= 1) return true;  // Problem line?
          palindrome(word);
      }
      else
          return false;
  }
  </code></pre>
  
  <p>For some reason when the recursive function gets deep enough, and word.length() is less than or equal to 1, It doesn't return true. I can't seem to figure out why. Is it something to do with how recursive functions work, or how I am readjusting the length of word in the line before I commented DEBUGGING?</p>
  
  <p>I am not as talented at C++ as I should be, so please excuse me if my programming seems poor.</p>