I am confused with my palindrome code.

#include <iostream>
#include <string>
using namespace std;

bool isPalindrome(string s);

int main()
{
string test = "A man, a plan, a canal - Panama!";
cout<<"Enter a phrase that will be tested"<<endl;
cin>>test;
cout<<(isPalindrome(test) ? "The phrase entered is a" : "The phrase entered is not a")<< " palindrome" << endl;
cin.sync();
cin.get();
return 0;
}

string cleanup(string s)
{

for (int i=0; i<int(s.length()); i++)
s= s.replace(i, 1, string(1, tolower(s.at(i))));

for (int i=0; i<int(s.length()); i++)
{
if (!isalnum(s.at(i)))
{
s = s.substr(0, i) + s.substr(i+1, int(s.length())-(i+1));
--i;
}
}
return s;
}
bool isPalindrome(string s)
{
string s2 = cleanup(s);
for (int i = 0; i < int(s2.length())/2; i++)
if (s2.at(i) != s2.at(int(s2.length())-1-i))
return false;
return true;
}

so far, when I run the program and enter "A man, a plan, a canal - Panama!", it works but when I enter "Never odd or even" it outputs: "This is not a palindrome" when it really is. Please help
Did you try using a debugger to see at what point it the logic isn't working? Also, please use [code][/code] tags in the future.
I'm not sure what you mean by a debugger.
I was given the code:

[
/* Converts all the characters of an input string to
lowercase and removes all the empty spaces and punctuation marks. */
string cleanup(string s)
{
//Converts all characters to lower case
for (int i=0; i<int(s.length()); i++)
s = s.replace(i, 1, string(1, tolower(s.at(i))));
//Remove spaces and punctuation marks
for (int i=0; i<int(s.length()); i++)
{
if (!isalnum(s.at(i)))
{
s = s.substr(0, i) + s.substr(i+1, int(s.length())-(i+1));
--i;
}
}
return s;
}
]
Topic archived. No new replies allowed.