//I am new to programming and having a problem with this code, I want to return the string if read back-words is in fact a palindrome. I am having an error on the line with return temp. The error says that cannot convert string into an int return. Really confused about this can someone elaborate on this and tell me how to resolve this issue.
if (length == 2)// at is for array and pointent ta begin and end
{
if (name.at(0) == name.at(1))
return true;
else
return false;
}
if (name.at(0) == name.at(name.length() - 1))
{
name.erase(name.end()-1); // earse last charcter from string
name.erase(name.begin()); // earse first charcter from string
return isPal(name); // ** recursion part
}
else
return false; // last one to check if all above aren't true
}
return exits a function. You have it in the middle of your main function. So at the end of your for loop you are basically trying to exit main by returning a string.
It works perfectly just removing the for loop inside main, probably some typo from old code. The following code compiles & works for me, reported without any formatting to be fair:
if (length == 2) // at is for array and pointent ta begin and end
{
if (name.at(0) == name.at(1))
return true;
else
return false;
}
if (name.at(0) == name.at(name.length() - 1)) {
name.erase(name.end() - 1); // earse last charcter from string
name.erase(name.begin()); // earse first charcter from string
return isPal(name); // ** recursion part
}
else
return false; // last one to check if all above aren't true
}