You have done a good effort, but there are a few things in the code to be changed.
I may be wrong, and hopefully someone might correct me.
// This may be the wrong way to pass it to the method (it has been a while since I had to do something like this). If it is, you should know how to do it.
bool is_palindrome(char *word, int size);
void main()
{
char q;
int n;
char *word[n];
cout<<"How many letters are in the word?"<
cin>>n;
cout<<"Enter the letters of the word, pressing enter after each"<
for (int i=0;i
{
cin>>*word[i];
}
if (is_palindrome(word, n)) // You may need to change how you pass the parameter 'word'. You should know yourself, or do some trial and error.
{
cout<<"The word you entered is a palindrome; a word that is spelled the same way both forward and backward"<
}
else
{
cout<<"The word you entered is not a palindrome"<
}
}
// This may be the wrong way to pass it to the method (it has been a while since I had to do something like this). If it is, you should know how to do it.
bool is_palindrome(char *word, int size)
{
// The following has been copied from the other answer. The other answer contained some errors though. The errors have been fixed. The &word[] may be wrong.
char *pEnd = &Word[size - 1];
char *pStart = &word [0]; // could also use pStart = word;
// now, find end of the word to start search
while ((pEnd != '\0') && (pEnd > pStart))
{
pEnd--;
}
if (pEnd != pStart)
{
pEnd--; // move to last char in word
}
else // This has been added.
{
return true;
}
// This has been changed.
while (pStart < pEnd)
{
// This has been changed.
if (*pStart != *pEnd) {
return false;
}
pStart++;
pEnd--;
}
// This has been changed to return a bool.
return true;
}