This is my simple program. However, I'm not getting correct results..
void main()
{
cout<<"Enter the sentence you want to check if it is palindrome or not"<<endl;
char sentence[100];
int length=strlen(sentence);
cin.getline(sentence,100);
bool palindrome=true;
for (int i=0;i<(length/2);i++)
{
if(toupper(sentence[i])!=toupper(sentence[length-i-1]))
{
palindrome=false;
break;
}
else
palindrome=true;
}
if(palindrome==true)
cout<<"This is a palindrome"<<endl;
else
cout<<"This is not a palindrome"<<endl;
{ill then consider copying my string into another one to ignore spaces in the sentence and marks, but for now i can't figure out why am i not getting a correct reslut upon entering the word racecar for example which is a palindrome, but is not displayed as so! I can't figure my logical error!