//
// Created by Fredrick Park on 2/26/17.
// Palindrome testing
// prompt user to enter a word, and we will check if palindrome or not.
// if true or false, output that result.
// code converts to lowercase and the checks palindrome
// input is not case sensitive


#include <iostream>
#include <string>
#include <cctype> // character manipulation library
using namespace std;

// function prototype for isPalindrome function
bool isPalindrome(string str); // returns true if palindrome, false otherwise
void toLowerCase(string & str);
// note, call by reference for input argument


int main() {
    string pal; string pal_input;
    bool ispal;
    cout << "Please enter a word and we will check if it is a palindrome: ";
    cin >> pal_input;
    pal = pal_input;
    toLowerCase(pal); // convert pal to lowercase
    ispal = isPalindrome(pal); // check if palindrome
    if (ispal == true) {
        cout << "\""<< pal_input << "\""<<  " is a palindrome";
    } else {
        cout << "\""<< pal_input << "\"" << " is not a palindrome";
    }
    return 0;
}

// function definitions
bool isPalindrome(string str) {
    for (int i = 0; i < str.length() / 2 ; i++ ){
        if (str[i] != str[str.length()-i-1]) return false;
    }
    return true;
}

void toLowerCase(string & str) {
    for (int i = 0; i < str.length(); i++) {
        str[i] = tolower(str[i]);
    }
}
