Program that checks if string is palindrome

Gahh I can't figure this out. I really just need help getting started.Thanks in advance if anyone can give me some tips where to start.

Write a program that will check if a word or a sentence is a palindrome. A palindrome is a word (or sentence) that is the same when read front to back and back to front.

In order to verify that a word is a palindrome it needs to be reversed and then compared to the original. If both are the same, then we can conclude it is a palindrome. Sentences need a bit more processing. All spaces, punctuation
marks have to be first removed from the sentence. Then in both word and sentence case we need to lower case all letters. Then sentence needs to be reversed and compared to the original compressed sentence.

Basically what I need to use is a do while loop with two more loops inside of it.

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
#include <iostream>
#include <string>

using namespace std;

int main()

{
	int i=0;
	int stringword;

	do{
			cout << "Enter a sentence to check: " << endl;
				cin >> stringword >> endl;

				while (i < stringword)
		
		stringword = tolower(stringword[i]);
		

		i++;
		
			cout << stringword << endl;

	  }



Thats all I have so far
Last edited on
Here's one approach:

Read in a string.
Copy the string.
Reverse the copy.
Is the copy still the same as the original?
If it is the same, it's a palindrome.
Yeah, but to reverse a string you do pretty much the same thing as when just checking for a palindrome in the first place.
I'd use std::reverse... I'm lazy. =P
1
2
3
4
5
6
7
8
bool is_palindrome( const std::string& str )
{ return std::equal( str.begin(), str.end(), str.rbegin() ) ; }

bool is_palindrome_nocase( const std::string& str )
{
    return std::equal( str.begin(), str.end(), str.rbegin(),
         [] ( char a, char b ) { return std::toupper(a) == std::toupper(b) ; } ) ;
}
Topic archived. No new replies allowed.