int main()
{
cout << "Enter a string: ";
string s;
getline(cin, s);
int low = 0;
int high = s.length() - 1;
bool isPalindrome = true;
while (low < high)
{
if (s[low] != s[high])
{
isPalindrome = false;
break;
}
low++;
high--;
}
if (isPalindrome)
cout << s << " is a palindrome" << endl;
else
cout << s << " is not a palindrome" << endl;
return 0;
}
Sample run:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Enter a string: radar
radar is a palindrome
Enter a string: city
city is not a palindrome
Enter a string: mom
mom is a palindrome
Enter a string: dad
dad is a palindrome
Enter a string: noon
noon is a palindrome
Enter a string: abc cba
abc cba is a palindrome
Enter a string: how now brown cow
how now brown cow is not a palindrome
Enter a string: END
There were 5 palindromes found
I'm sorry that I'm a noob, just need a little help.
Ooh never mind but your harsh reply is way off topic and doesn't prove to solve ops question at hand in any manner, atleast try to be friendly , it doesn't hurt I promise you.
Oh come on @Andy1992. It is beyond obvious that my response was sarcasm. This is a beginner section. And he is apologizing for being a noob, who does that? Everyone has been a noob in their programming career, that is not something you apologize for...
It Was sarcasm and a joke so lets calm out tits shall we :)