Palindrome Program. Help Please!

My job is to read in a line of data from an input file, remove all white space and punctuation, then check to see whether or not it is a palindrome. The input file is an arbitrary length long including no input. I need to read in a line of data at a time then process it until there is no more data to process.
The output should look something like this.

Input Value: Sit on a potato Pan otis!!!
Is it a palindrome? Yes

Input Value: race car
Is it a palindrome? Yes

Input Value: wooHaaaaa
Is it a palindrome? No

I am very new to Programming so anything that you smarter people can do to help me would be greatly appreciated!
This is what I have right now:

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

ifstream infile;
ofstream outfile;

int main()
ifstream inData;
ofstream outData;
char sentence[90];"InPalindrome.txt");"OutPalindrome.txt");

if (!inData)
cout << "Can't open input file successfully";
getchar ();
return 1;
if (!outData)
cout << "Can't open output file successfully";
getchar ();
return 2;

outData << "Input Value :"<<endl;

inData >> sentence;

int x = strlen(sentence)-1;

for(int i = 0; i <= x; i++)
if (sentence[i] == sentence[x-i])
outData<<"Sentence is a palidrome"<<endl;
getchar ();
return 0;

outData<< "Sentence is a Palidrome"<<endl;

getchar ();
return 0;

My debug is successful but it just doesn't work how I would like it too
Thanks again!
Last edited on

first of all, please use code tags. makes your code a lot easier to read for us! thnks.

first thing i noticed you open the file inside a while loop.
What you need to do is open the file en then get all the data out.
Not open it every time:

ifstream inData;"InPalindrome.txt");
string sentence;
  /* get sentence */
  getline (inData,sentence);

  /* check palidrome ( I did not check this part )*/

Hello thanks for replying!

I am kind of confused on how to integrate what you told me to do, into my program.
I started over because something happened with my visual studio and took a slightly different approach. I posted the new code in a new topic discussion

Topic archived. No new replies allowed.