The problem is I have to use -32 to identify the uppercase or lowercase characters in a palindrome (its for school)
kainjows answer I think is on the right track but doesn't seem to work quite right
here is my full code
<snip>
It has to check so that it ignores uppercase and lowercase
for eg these would all be palindromes
AbBa
aBbA
ABbA
abba
ABBA etc
I am pulling my hair out
lee1210 I am sure your answer is correct but it to advanced for what I have been taught already so I cant really use it.
I know in my head my answer should work but it just doesnt
I would still insist, if you are not allowed to use things from the libraries, on making your own toupper in your program and using that. It would be extremely easy:
Code:
char myToUpper(char input) {
char result;
if(input >= 'a' && input <= 'z') { //Lower case letter
result = input + ('A'-'a'); //It's fine to do 32, but unless you know ascii by heart, this is clearer.
} else {
result = input;
}
return result;
}
I am not too familiar with the AnsiString class, I'm not too experienced with C++, but does Length(AnsiString) return the same thing as AnsiString.Length()?
If what you have isn't working, I would dig in with a debugger (if you are using gcc/g++ to compile, add the -g option, then invoke gdb on the program produced), or fall back to the good old debug print statements. I would print what is returned from the Length call, then what Front and Back are each iteration of the loop, and what CharA and CharB are. If you want to really check things out, you can also print the values of:
(CharA != CharB)
(CharA != (CharB - 32))
(CharA != (CharB + 32))
or if you make your own toupper, just:
(myToUpper(CharA) != myToUpper(CharB))
I didn't see anything glaringly wrong. I thought I saw an off-by-one with the indicies for AnsiString, but didn't realize it was 1-based (i think it might damage my psyche to work with a C-based language using classes that were 1-based instead of 0-based).
Good luck.
-Lee