Q:

Bool function always returning false

Hi my trying to create a function that lets the user know if the word entered is a palindrome (is the same spelled backwards, ex: kayak). This is the function I came up with, yet for some reason the function always return false.  
#include <iostream>
#include <cctype>
using namespace std;

bool compare(string str2)
{
    int first = 0, mid, last = (str2.size() - 1);

    while(first < last)
    {
        if(first == last)
        {
            first++;
            last--;
        }
        else return(false);
    }
    return(true);  
}

int main()
{
    string pal;

    cout <<"Enter your single word palindrome: ";
    getline(cin,pal);

    if(compare(pal) == true)cout << pal <<" is a palindrome.\n";
    else                    cout << pal <<" is not a palindrome.\n";

    return(0);
}

A:

You aren't actually doing any character comparison, just comparing the indexes first and last - they don't match so you return false.

