Hello.
I'm doing an exercise whereby I need to test if a word is a palindrome.
My code for the function is as follows:
#include "test_palindrome.h"
using std::string;
bool is_it_palindrome(const string s)
{
bool palindrome = true;
for(string::const_iterator iter = s.begin(); iter != s.end(); ++iter)
{
string::const_reverse_iterator rit = s.rbegin();
if(*iter!=*rit)
palindrome = false;
++rit;
}
return palindrome;
}
It compiles but when I enter any word, regardless of whether it is a palindrome or not, it comes up as false.
Why is this?
Cheers.