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:

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

November 6th, 2012, 09:54 AM

GCDEF

Re: I need help with my basic program

"My debug is successful but it just doesn't work how I would like it too"

That's a contradictory statement. What doesn't work? Off the top of my head I see your loop checks the entire string, when it should stop in the middle.

November 6th, 2012, 10:55 AM

Rookie24

Re: I need help with my basic program

I was meaning to say that when I build the solution it is successful but I really dont know how to get the outcome that I need

November 6th, 2012, 11:42 AM

GCDEF

Re: I need help with my basic program

It would really help if you said how its behavior differs from what you want

November 6th, 2012, 12:05 PM

Paul McKenzie

Re: I need help with my basic program

Quote:

Originally Posted by Rookie24

I was meaning to say that when I build the solution it is successful

OK, you should understand something really basic.

Building a C++ program successfully only means that your code is syntactically correct, and that the linker finds all of the external functions your application calls. That's it, nothing else.

Nowhere does a successful build of an application ensures that the application will work correctly. If I was told to write a program to add two numbers, but instead the application subtracts the two numbers, does the application compile and build successfully? Yes. However, does the program work correctly (adds two numbers). No.

So now what you should be doing is to debug your program. Debugging a program that you wrote is part and parcel of learning how to write programs. It isn't just about writing code, running the code, and then posting on CodeGuru or some other forum that your program doesn't work. You have to take the program you wrote and identify by debugging where it goes wrong. No one writes flawless, bug-free programs every single time, and debugging is the mechanism used to figure out what is wrong with the program.

Regards,

Paul McKenzie

November 6th, 2012, 03:36 PM

Rookie24

Re: I need help with my basic program

My program right now is just outputting to the screen the first 3 lines of my input file when I run the program. I need it to read in all of the lines, determine if the phrases are a palindrome or not and then it needs to produce an output report both to the screen and to an output file. The output should look like this:

Input Value: race car
Is it a palindrome? Yes

Input Value: mom
Is it a palindrome? Yes

Input Value: pop
Is it a palindrome? Yes

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

Input Value: program
Is it a palindrome? no

Input Value: wooHaaaaa
Is it a palindrome? No

However, the output to the screen that I am getting is:

race car
mom
pop

Thanks again for your help, I really appreciate it

November 6th, 2012, 03:54 PM

GCDEF

Re: I need help with my basic program

This really is the time to learn to use the debugger. It'll show you everything your program is doing and why it's doing it. It's absolutely indispensable, and it's what every one of us here would do to find out what your program is doing. You really can't write even simple programs without it.

November 6th, 2012, 04:46 PM

Paul McKenzie

Re: I need help with my basic program

Quote:

Originally Posted by Rookie24

My program right now is just outputting to the screen the first 3 lines of my input file when I run the program. I need it to read in all of the lines, determine if the phrases are a palindrome or not and then it needs to produce an output report both to the screen and to an output file. The output should look like this:

Again, writing and debugging programs is something you must learn to do. Just saying that "I wrote a program and it doesn't work. Make it work for me" isn't going to get you far here.

I know you're a beginner, but you have to understand that it isn't "wrong" to have a program that doesn't work correctly initially. That's the nature of programming -- all of us have written and still write programs that initially do not behave correctly. That is where the other part comes in, and that is debugging. This is where you take a program that doesn't behave correctly, and correct it.

You wrote the program therefore you had something in mind when you wrote the program. So take the debugger, step through your program, and see where the program deviates from the original plan. Again, you wrote the program -- if you wrote the program, you must know what you're doing every single step of the way, else you could never have written it. Now if the program doesn't behave correctly, you know exactly what parts of the code are supposed to do "x", and if it doesn't do "x", you fix it by debugging it.

Also, you should use code tags when posting code so that the code is formatted and readable.

Regards,

Paul McKenzie

November 6th, 2012, 05:49 PM

GCDEF

Re: I need help with my basic program

One other thing, since we don't have your input file, none of us can reproduce what you're seeing without guessing.