I'm trying to make a code that prints out if the word is a palindrome or not.
but the code always tells me that the word is not a palindrom when i input a palindrome word. i think the error is in the for but i'm not sure.
constint SIZE = 51;
int main ()
char line [SIZE];
cout<<"Enter a word no more than 50 characters."<<endl;
for (int count=length-1, i=0; count>=0; count--, i++)
cout<<"The word is a palindrome."<<endl;
cout<<"The word is not a palindrome."<<endl;
It is quite easy to figure out if a word is a palindrome once you figure out how. The best way to go about it is to make a function that does it for you. The function should return true if the words is a palindrome or false if it isn't.
To go about making this function just follow these steps.
1) Make you function, the function should return a bool and it should have only 1 parameter that is a const string& to the word you want to test. bool isPalin(const std::string &word) is how it could look.
2) In your function you need to reverse the string you want to test. The reason why you want to do this is because if the reversed string matches the original string it will be a palindrome. So figure out a way to reverse the string.
Hint: All you need to do is use the strings constructor with rbegin() and rend(). Remember that you can create a string by using 2 iterators.
3) Make a if else condition that test if the reversed string is equal to the original string. If it is return true. If it isn't return false.
And boom you have a function that can tell you if the string is a palindrome.
Let me know if you have any problems or don't understand anything.