I can't get the do-while loop in water to work. It will take a positive number and then return the right thing and quit the program, but if given a negative number it spits out a negative water amount and then asks for another bottle amount. The code I have right now is the only one I can get that won't give me error messages, but I can't figure out this last bit.

Here's my code

Thank you!

2 Answers 2


Your code is actually doing what you told it to, but you told it to print out the number of bottles before it exited the for-loop. A simple fix is to put the printf outside the for-loop.

If you still have issues/questions, comment below.


There is no structural error in this code. but problem is in your printf function which is in do while loop. As if you inut negative no then do while loop will execute once and print your answer.so its better to apply printf fuction after dowhile loop.and also take care of scope of variable. if you further get any error reply me here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .