I have been working on this for 8 hours and i'm and still having problems with the bool palindrome definition at the end of the program. when i execute it always comes up as palindrome true even if it's not. please help
// A Program that lets a user enter a line of text and states
// weather or not the line is a palindrome
#include <iostream> // provides cout, etc.
#include <fstream> // provides file functions
#include <cstdlib> // provides exit()
#include <cstring> // provides strlen()
using namespace std;
const int MAXSTRINGSIZE= 80; // no more than 79 characters used
const char SENTINEL[]="stop!"; // used to end data entry
void explain_prog(ostream& os);
// Explains what the program does
void read_string(istream& is,char s[],int maxlength);
// postcondition: a string s of at most maxlength-1 characters has
// been read from input stream is
void write_string(ostream& os,const char s[]);
// precondition: string s has a value
// postcondition: s is written to output stream os
void blank_remover(const char s1[],char s2[]);
// precondition: s1 has a value
// postcondition: s2 is s1 with all the blanks removed
bool palindrome(const char s[]);
// precondition: s is a string with all blanks removed
// postcondition: value true returned if s is palindrome
// otherwise false is returned
int main()
{
char s1[MAXSTRINGSIZE], // holds one line of text
s2[MAXSTRINGSIZE]; // s1 with all blanks removed
bool pal; //true if s1 is a palindrome, otherwise false
ofstream fout; // internal name for output file
explain_prog(cout); // explain program to User at terminal
// open output file - check for errors opening
fout.open("pal.out");
if(fout.fail())
{
cout << "\nOutput file opening failed!\n";
exit(1);
}
// document output file
fout << "\nJustin Cochrane CMSV1180\nAssignment #9 Question #1\n\n";
explain_prog(fout);
// get first line or SENTINEL
cout<< "Please enter line of text or" <<SENTINEL<<endl;
read_string(cin,s1,MAXSTRINGSIZE);
while(strcmp(s1,SENTINEL)!=0)
{
fout<< "\nLine entered.";
write_string(fout, s1);
// remove blanks from s1 and store in s2
blank_remover(s1,s2);
pal=palindrome(s2);
if(pal)
{
cout<< "line of text is a palindrome";
fout<< "line of text is a palindrome";
}
else
{
cout<< "line of text is not a palindrome";
fout<< "line of text is not a palindrome";
}
//get next line of text or SENTINEL
cout<< "Please enter a line of text or"<<SENTINEL<<endl;
read_string(cin,s1,MAXSTRINGSIZE);
}
// close files
fout.close();
return 0;
}
void explain_prog(ostream& os)
{
os << "\nThis program lets a user enter a line of text "
<< "and states weather it is a palindrome or not";
}
void read_string(istream& is, char s[], int maxlength)
{
char ch; //used to read eoln character
is.get(s,maxlength);
is.get(ch); //read eoln character
}
void write_string(ostream& os, const char s[])
{
os <<s<<endl;
}
void blank_remover(const char s1[],char s2[])
{
int n=strlen(s1); // characters in s1
int j=0; // index for s2
for(int i=0; i<n; ++i)
{
if(s1[i]!=' ')
{
s2[j]=s1[i];
++j;
}
}
s2[j]='\0'; // put null character in s2
}
bool palindrome(const char s[])
{
bool pal=true; // assume s is a palindrome until mismatch is found
int start=0;
int end=strlen(s);
while(start<end)
{
end--;
start++;
bool pal=false;
}
return start;
}[CODE]