Hi I am trying to write a program that will determine if a set of characters is a Palindrome or not. I can get it to run, but everything I enter is determined a Palindrome. How do I fix it so that the boolean value changes? Below is the 'for-loop' that should be changing the value, but isn't. Thanks
for (int i = 0; i < length/2; i++)
{
if (s[i] == s[length-1])
{}
I see no error in that code snippet, so the error is somewhere else. Post your full code.
Also: i = length/2;
Don't do this! This is what break exists for.
ok. So I ran it..and it will identify words/characters less than 3 characters but it won't pick up on "noon" or "hannah"....it calls those non palindromes...ugh! help! any pointers? Thanks!
You're comparing each character to the very last character in the string. So your code will think "nnnnooon" is a palindrome because all character before the halfway point match the last 'n'.