-
November 6th, 2012, 10:38 AM
#1
I need help with my basic program
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. A palindrome is a word or phrase that is the same backwards as it is forward like RACECAR.
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;
while(!infile.eof())
{
char sentence[90];
inData.open("InPalindrome.txt");
outData.open("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])
{
continue;
}
else
{
outData<<"Sentence is a palidrome"<<endl;
getchar ();
return 0;
}
}
outData<< "Sentence is a Palidrome"<<endl;
}
inData.close();
outData.close();
getchar ();
return 0;
}
My debug is successful but it just doesn't work how I would like it too
Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|