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.