Program to check whether text is a pallindrome | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Program to check whether text is a pallindrome

Why is this program not functioning. I am getting compiler errors in the function " string was not declared in this scope" https://code.sololearn.com/cA13a17A11A1/?ref=app

28th Jan 2021, 9:07 AM
Reynolds Onyango
Reynolds Onyango - avatar
2 Answers
+ 6
There are multiple issues in your code: 1. Your parameter is called 'a', not "stringa". 2. Strings are not C-strings, you can't use strlen() directly on them. Use the built-in methods length() or size() instead, e.g. a.size(). 3. The control flow of your function is incorrect, because right now you make the palindrome decision based on the first and last character only, as the function will immediately return. Here is how it could look like if you correct the points I mentioned above: https://code.sololearn.com/czPRfdZKUCJL/?ref=app
28th Jan 2021, 9:34 AM
Shadow
Shadow - avatar
+ 5
Reynolds Onyango Because there is no stringa in your code, there is only a in method. You need to get length of using length () method in c++ https://code.sololearn.com/czCPUAqMoBpV/?ref=app
28th Jan 2021, 9:27 AM
A͢J
A͢J - avatar