Code
#include <iostream>
#include <string>
using namespace std;
bool isPalindrome(string str)
{
for(int i = 0; i <= str.length()-1; i++)
{
if(str[i] != str[str.length()-1-i])
{
return false;
}
else
{
return true;
}
}
}
int main()
{
string text;
do
{
cout << "Enter some Text: " << endl;
cin >> text;
if(isPalindrome(text))
{
cout << "The text is a palindrome" << endl;
}
else
{
cout << "The text is not a palindrome" << endl;
}
}while(text != "Q");
return 0;
}
Input_1
otto
Output
The text is a palindrome
Input_2
ottop
Output
The text is a palindrome
Input_3
ottopo
Output3
The text is a palindrome
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.