Exiting While loop

I'm working on code for a program and am stuck trying to cleanly get out of my loop. Here's the code:


I'm trying to figure out a way out of the loop with out having the cout show up again. I'm sure I'll probably figure it out in the morning with a fresh nights sleep but will take any suggestions. I still need to clean the code up a bit too.
Last edited on
while(hit!=9)
maybe this is the problem... could you post your full code?
Maybe indentation is problem.
like chipp said, please post your full code.
add the line cout<<hit<<endl; at the end of the loop so you can see what happens with your hit var .
Last edited on
You could change line 20 to

1
2
if ( ++hit == 9 )
    break; 


Of course, then there's no reason to have a loop condition at all. Better would be to structure the loop so that the block of code you currently have after the if/else if construction is above it, perhaps in a do/while loop.
Topic archived. No new replies allowed.