Hello,
I have created a basic palinedrome program that works fine when obtaining words using commands like , but I would like to elaborate and gets full sentences as inputs. I tried using the getline command, but my program crashes tremendously when in use. Maybe I am using it improperly? Some of my code is posted below:
Code:
getline(cin, input);
while (input[0] != '0') {
front = 0;
back = input.length() - 1;
palindrome = true;
while (done == false) {
input[front] = tolower(input[front]);
input[back] = tolower(input[back]);
if (input[front] == input[back]) {
front++;
back--;
} else {
palindrome = false;
done = true;
}
if (front >= back) {
done = true;
}
}
if (palindrome == true) {
cout << "\"" << input << "\"" << " is a palindrome." << endl;
} else {
cout << "\"" << input << "\"" << " is not a palindrome." << endl;
}
done = false;
getline(cin, input);
}
Any suggestions or ideas would be greatly appreciated. Take care.