confused (switch help)

This is a discussion on confused (switch help) within the C Programming forums, part of the General Programming Boards category; Ok so I'm refreshing my C by going through an old Primer book before my upcoming classes this fall and ...

confused (switch help)

Ok so I'm refreshing my C by going through an old Primer book before my upcoming classes this fall and I'm having trouble.

The book is asking me to make a program that let's you choose what item your ordering, enter the pounds, then when you're done entering the various weights it will print out the totals, shipping, and what you ordered. Most of this is easy and I can handle all of the computations and such but for some reason my switch isn't working right.

It seems like the breaks aren't working right or something. For some reason the overlying while loop wants to read the input given for the order function. I've been tweaking it and got it to appear to work right when you first choose an item and then enter the weight, but it breaks down to multiple reading again after that. I'm not even sure quite how my changes made it work better, and am even more confused that it only works once.

Thanks for your help, and if this isn't the right forum please let me know of one I can go to for advice.

ah true thanks, though as you can see with the // I originally was using a while loop with getchar(), and even tried an if statement. Of course far as I know I'll have to stick with While so it keeps going until the user quits.

I think flushing the your problem was that you wernt flushing the new lines in the input buffer. When I teseted you code it screwed up after the first loop, I made a small change and now it works for me (in bold).

thanks guys, and especially on the little addition. The book had a similar line in an example program but they use it to force it to only read the first character (i.e. someone inputs "dab" instead of "d") so I didn't think to use it. I forgot about the whitespace problem.

Thanks again guys, hopefully I can get the shipping function working without any problems.