I need to write a program that:
-makes the user input something then it checks if the user has a palindrome or not
-treats capital and lower case letters the same. For example, "a" and "A" should be the same
-it has to exit the program if the user input contains a "q" or "Q"
-removes all spaces from the user input
-only <string> and <iostream> are allowed to be used
-can only use getline, replace, erase,length and find string functions
20:13: error: 'isPalindrome' was not declared in this scope
You need to define a bool isPalindrome; somewhere in main.
Looking at your logic, it looks like you want to initialize it to true, so it would be: bool isPalindrome = true;, put it somewhere before your for loop.
-treats capital and lower case letters the same
Simplest solution is to change if (str[i] != str[(length - 1) - i])
to if (tolower(str[i]) != tolower(str[(length - 1) - i]))
To compare both characters to a common lowercase.
BUT -- you need to #include <cctype> for this, technically... it might still work if you don't, but it isn't guaranteed to work.
You can also make your own "tolower" function, by comparing ASCII values. http://asciitable.com
After minor changes to make it compile, your code works with "friendly" input (all lower case, no spaces).
To handle the case and spaces, I strongly recommend that you write code to create a second "normalized" string from the input. You copy the input string character by character to the normalized string, except:
- change lower case to upper case
- skip spaces
- set a flag if you see "q" or "Q".
Then use your existing code to see if the normalized string is a palindrome.