need help to check if a word is a palindrome

hi am new to c++... how do I check if a word is a palindrome

although I browsed de code online but I kept getting (expected ' before "break"
here is de code
#include<iostream>
using namespace std;
int main(){
char string1[20];
int i, length;
int flag = 0;
cout << "Enter a string: ";
cin >> string1;
length = strlen(string1);
for(i=0;i < length ;i++){
if(string1[i] != string1[length-i-1]){
flag = 1;
break;
}
}
if (flag) {
cout << string1 << " is not a palindrome" << endl;
}
else {
cout << string1 << " is a palindrome" << endl;
}
system("pause");
return 0;
}

I would also be happy if a comment line is used to explain de code
Last edited on
Topic archived. No new replies allowed.