FAQ: Code Challenge: C++ Functions - Palindrome

I am sorry to say this but the program you wrote does not work, because you are not changing the value of n inside the for loop.

So I’m quite proud of myself with how I’d done it. Here’s my code:

//takes text and returns true for palindrome, false for non palindrome.

#include <iostream>
#include <vector>

bool is_palindrome(std::string text) {
    int minusone = text.length() - 1;
    std::string backtext = "";
    std::vector<char> letters;
    for (int i = 0; i < text.length(); i++) {
        letters.push_back(text[i]);
    }
    for (int i = minusone; i > -1; i--) {
        backtext.push_back(letters[i]);
    }
    if (text == backtext) {
        return true;
    }
    else {
        return false;
    }
    

    

}

int main() {
  
  std::cout << is_palindrome("madam") << "\n";
  std::cout << is_palindrome("ada") << "\n";
  std::cout << is_palindrome("lovelace") << "\n";
  
}