This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Welcome to the Ranch! Please UseCodeTags when you post source code, and make sure your code is properly indented. That way it is much easier to read. Being a moderator on the forum here, I have added the code tags to your post above.
What do you mean with "the while loop doesn't exit"; what happens when you enter -1 for the gallons?
I tried running your program, and when I enter -1 for the gallons, it first asks for the miles and then exits, as you would expect.