Tuesday, July 14, 2009

C programming continue loop?

How do I add this statement in a c programming structure?





"Prompt the user to enter 'c' to continue or 'q' to quit"





I suppose you would use some sort of loop but im not sure how to impliment it.

C programming continue loop?
you can have a while loop based on flag 'keep_going', set keep_going to 'c' and as long as keep_going is equal to 'c', run the loop. If you need to only quit if 'q' is typed and not some other letter, then you could say, while keep_going != 'q' and then do a check inside your loop to make sure it isn't some other random letter either.
Reply:Try using a printf followed by a getchar.





You can wrap them both in a do while loop waiting for a valid answer to be entered.


No comments:

Post a Comment