![]() |
my loop exits early
I'm working on a program that reads in a line of text from the user and then runs a free function(palidrome) to see if the text entered in a palidrome. The loop should prompt user for line of text then run palidrome which returns a bool, tell the user if it is a palidrome, then askes the user for another line of text until <ctrl-z> is entered. for some reason it askes for the palidrome and then exits. Can't figure it out.
:
int main(){ |
Quote:
i put the curly braces in...........very badly i know |
There is no call to cin.get inside your inner loop, so it will loop forever.
|
Umm... if we are being anal about it this:
:
if(palindrome (S,Q)) |
Yup, I like the cleaner braceless look too for short conditions; I actually think it's clearer and easier to read. A lot of people disagree with us about that though.
|
I agree that it's cleaner. If the block is short, I may even put it on the same line. At the same time, I recommend that novices go for the braces, even for one liners. This insures that if they add a debug statement, the suddenly-longer block will still be a block.
On the other hand, I would certainly never unilaterally add unnecessary braces to another's post, in the name of "correcting a mistake." |
Quote:
|
hey i already said, if i knew how to delete that post i properly would, and i already said it was really bad. curly braces make it easier for others to look over your work (okay don't refer to my example....i cannot over emphasises how wrong it is).
|
| All times are GMT -5. The time now is 1:39 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC