title: C++ palindrome function
body: <p><strong>Code</strong></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  bool isPalindrome(string str)
  {
      for(int i = 0; i &lt;= str.length()-1; i++)
      {
          if(str[i] != str[str.length()-1-i])
          {
              return false;
          }
          else
          {
              return true;
          }
      }
  }
  
  int main()
  {
      string text;
  
      do
      {
          cout &lt;&lt; &quot;Enter some Text: &quot; &lt;&lt; endl;
          cin &gt;&gt; text;
          if(isPalindrome(text))
          {
              cout &lt;&lt; &quot;The text is a palindrome&quot; &lt;&lt; endl;
          }
          else
          {
              cout &lt;&lt; &quot;The text is not a palindrome&quot; &lt;&lt; endl;
          }
  
      }while(text != &quot;Q&quot;);
  
      return 0;
  }
  </code></pre>
  <p><strong>Input_1</strong></p>
  <pre><code>otto
  </code></pre>
  <p>Output</p>
  <pre><code>The text is a palindrome
  </code></pre>
  <p><strong>Input_2</strong></p>
  <pre><code> ottop
  </code></pre>
  <p>Output</p>
  <pre><code>The text is a palindrome
  </code></pre>
  <p><strong>Input_3</strong></p>
  <pre><code>ottopo
  </code></pre>
  <p>Output3</p>
  <pre><code>The text is a palindrome
  </code></pre>
  <p>I want to check the string entered from user is palindrome or not ? Why Output for my 3rd input is getting wrong ? I think I am missing something.</p>