You shouldn't have that break
before the return
statement in the first if
and also shouldn't return true
in the second because you don't finish the loop.
You can do the whole thing like this:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool isnotalpha(char c){return !isalpha(c);}
int main(void)
{
string updated1="AbbA",updated2;
transform(updated1.begin(),updated1.end(),updated1.begin(),tolower);
updated1.erase(remove_if(updated1.begin(),updated1.end(),isnotalpha),updated1.end());
updated2=updated1;
reverse(updated2.begin(),updated2.end());
bool palindrome=true;
for(int i=0; i<updated1.length(); i++)
{
if(updated1[i]!=updated2[i]) palindrome=false;
//if(updated1[i]!=updated1[updated1.length()-1-i]) palindrome=false; Can be done without using updated2
}
if(palindrome) cout << "Palindrome!" << endl;
else cout << "Not Palindrome!" << endl;
return 0;
}