Palindrome Checker help

I have the code, I just need to add a loop until the user inputs END.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
int main()
{
	cout << "Enter a string: ";
	string s;
	getline(cin, s);
	
	int low = 0;
	
	int high = s.length() - 1;
	
	bool isPalindrome = true;
	while (low < high)
	{
		if (s[low] != s[high])
		{
			isPalindrome = false;
			break;
		}
		
		low++;
		high--;
	}
	
	if (isPalindrome)
		cout << s << " is a palindrome" << endl;
	else 
		cout << s << " is not a palindrome" << endl;
		
	return 0;
}


Sample run:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Enter a string: radar
radar is a palindrome
Enter a string: city
city is not a palindrome
Enter a string: mom
mom is a palindrome
Enter a string: dad
dad is a palindrome
Enter a string: noon
noon is a palindrome
Enter a string: abc cba
abc cba is a palindrome
Enter a string: how now brown cow
how now brown cow is not a palindrome
Enter a string: END
There were 5 palindromes found


I'm sorry that I'm a noob, just need a little help.
Last edited on
1
2
3
while(getline(cin, s) && s != "END") {
    ...
}


1
2
3
for(getline(cin, s); s != "END"; getline(cin, s)) {
    ...
}
Last edited on
I'm sorry that I'm a noob,


You should be ashamed of yourself.
closed account (SECMoG1T)
@Tarikneaj Answer Questions in a Helpful manner.
Last edited on
@Andy1992 I wasnt answering his question.
closed account (SECMoG1T)
Ooh never mind but your harsh reply is way off topic and doesn't prove to solve ops question at hand in any manner, atleast try to be friendly , it doesn't hurt I promise you.
Last edited on
Oh come on @Andy1992. It is beyond obvious that my response was sarcasm. This is a beginner section. And he is apologizing for being a noob, who does that? Everyone has been a noob in their programming career, that is not something you apologize for...

It Was sarcasm and a joke so lets calm out tits shall we :)
Topic archived. No new replies allowed.