Hi,I am a c++ beginner.
I am using vs,and I got a problem in my code which check a sentence whether a palindrome or not.
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main ()
{
bool palindrome = true;
char character;
StackType stack;
Queue queue;
char stackChar;
char queChar;
cout << "Enter a string; press return." << endl;
cin.get(character);
while ( character != '\n' && character != '.')
{
if ( isalpha (character))
{
character = tolower(character);
}
stack.Push ( character );
queue. enqueue ( character );
cin.get ( character );
}
while ( palindrome && !queue.isEmpty () )
{
stackChar = stack.Top ();
stack.Pop ();
queue.dequeue ( queChar );
if ( stackChar != queChar )
palindrome = false;
}
if ( palindrome )
cout << "String is a palindrome." << endl;
else
cout << "String is not a palindrome." << endl;
return 0;
}
Enter a string;press return.
Eve
String is a palindrome.
Enter a string;press return.
Eve,eve.
String is a palindrome.
It seems ok, but when I test this:
Enter a string;press return.
Able was I ere, I saw Elba.
String is not a palindrome.
but "Able was I ere, I saw Elba." in the assignment example is a palindrome.
can anyone tell me whats wrong with my code? please.