I am having trouble with my palindrome function.... here is the code for the whole program... the code for the palindrome function is at the bottom:
#include <cstdlib> #include <iostream> #include <iomanip> #include <cctype> const int N=80; using namespace std; void read(char x[], int& i); void upper(char x[], int i); bool palin(char x[], int i); int main() { char x[N]; int i=0; read(x,i); upper(x,i); if(palin(x,i)) { cout<<"The string is a palindrome."<<endl; } else { cout<<"The string is NOT a palindrome."<<endl; } return EXIT_SUCCESS; } void read(char x[], int& i) { char ch; cout<<"Enter a line that might be a palindrome:"<<endl; cin.get(ch); while ( ch >= ' ' ) { if(isalpha(ch)) x=ch; ++i; cin.get(ch); } } void upper(char x[], int i) { char ch; cin.get(ch); for(int n=0; n<i; ++n) { ch = toupper(ch); x[n]=ch; } } bool palin(char x[], int i) { int leftch=0; int rightch=i-1; if(x[leftch]==x[rightch]) { ++leftch; --rightch; return true; } else { return false; } }