Can you please review my program, it reverses the words just fine but I need help with telling the user if it is a palindrome or not. Anything is really appreciated.
#include <iostream>
#include <string>
usingnamespace std;
string compress(string s)
{
string result;
for (int i = 0; i < s.size(); i++)
{
if (isalpha(s[i]))
{
result += tolower(s[i]);
}
}
return(result);
}
string reverse(string s)
{
string result;
for (int i = 0; i < s.size(); i++)//in essence this resizes the string so it can hold all the characters
{
result += s[s.size() - i - 1];
}
return(result);
}
void palindrone(string &compressed, string &reversed) //checks to see if the original word and the reversed word match
{
if (compressed == reversed)
{
cout << "It is a palindrome"<<endl;
}
else
{
cout << "It is not a palindrome"<<endl;
}
}
int main()
{
string input;
cout << "Enter a sentence to check:"<<endl;
getline(cin, input); // gets whole line instead of one word
string compressed = compress(input); //calls the compressed input
cout << "Compressed input: " << compressed <<endl;
string reversed = reverse(compressed); //calls the compressed word into reverse
cout << "Reversed input: " << reversed <<endl;
palindrone; //calls palindrone
system("pause");
return (0);
}