Question: Based on the code below, I'm supposed to Write a C++ program that determines if a given string is a palindrome. When I enter in

Based on the code below, I'm supposed to Write a C++ program that determines if a given string is a palindrome. When I enter in a string, it's supposed to properly tell me if it's a palindrome or not. The problem is that no matter what I enter, it tells me what I enter isn't a palindrome. I need help correcting this error in the code below.

#include #include using namespace std; //function prptotypes eclared void transform( char *raw, char *testStr); bool testPalindrome(char *str); int main() { //char arrays declared char str[80]; char convertedStr[80]; //reading string from user cout<<"Enter String: "; cin >> str; //calling functions to remove unwanted characters transform( str, convertedStr); //calling function to check palindrome or not bool res = testPalindrome(convertedStr); if(res){ cout<<" Entered String is Palindrome"; } else{ cout<<" Entered String is not a Palindrome"; } return 0; } //this function will convert all letters to upper case and remove unwanteed extra caracters void transform( char *raw, char *testStr){ int strlength = strlen(raw); int front = 0; for(int i = 0; i < strlength; i++) { raw[i] = toupper(raw[i]); //converting to upper case } for(int i = 0; i < strlength; i++) { if(isalpha(raw[i])){ //checking for aonly alphabets testStr[front] = raw[i]; front++; } } } //palindrome checking function bool testPalindrome(char *str){ bool result = true; int strlength = strlen(str); //getting string length for(int i=0, j = strlength-1; i< strlength/2;i++,j--){ //palindrome checking if(str[i]==str[j]){ //checking from front and back result; break; } else { result = false; } } return result; //returning result }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!