I want my loop program to quit after END is entered. However, my program ignores my condition and keeps looping. Can anyone point out what I need to fix?
while (x != "END")
{
getline(cin, x);
p = x;
xx=x;
x = Pal(x);
x = Reverse(x);
x = Filter(x);
p = Pal(p);
p = Filter(p);
if ( p == x )
{
cout << xx << " is a palindrome." << endl;
}
else
{
cout << xx<< " is NOT a palindrome." << endl;
}
}
so below,the code will do what you want it to do,(sort of)
the reason why I say sort of is because although the program will end when you enter "END" it will still print END is not a palindrome you could instead create an infinite while loop and break from the loop if xx is equal to "END"
also there is no need to include a lot of them headers in the program for trivial programs such as this they won't do much harm but having so many includes makes the executable larger,don't include them if you don't need them.
int main ()
{
string x;
string p;
string xx;
while (xx != "END")
{
getline(cin, x);
p = x;
xx=x;
x = Pal(x);
x = Reverse(x);
x = Filter(x);
p = Pal(p);
p = Filter(p);
if ( p == x )
{
cout << xx << " is a palindrome." << endl;
}
else
{
cout << xx<< " is NOT a palindrome." << endl;
}
}
}
You could try something like: while (getline(cin, x) && x != "END") for your loop control statement. And remember "end" is not the same as "END" or "End", etc.