Well - the best way to find out is to use a debugger.
This is a tool which allows you to run your program and look at exactly what is happening while it runs.
Put a breakpoint on the line
while(n != 0){
And run your program. When it reaches the line it will stop to allow you to decide what happens next, and to look at what is in the variables.
Step through your program a line at a time, working out what you expect to happen each time, and comparing it to what does happen. If they aren't the same, then why not?
If they are, move on to the next line and keep going until something looks wrong.
When you find a difference, it should be reasonably obvious what the problem is!
This is a skill - predictably called debugging - which like all skills you only develop and improve by using. And it's a lot easy to learn when you are working with a tiny program like this one than later when you have half a million lines of code and don't know where the problem is! :laugh:
Give it a try - it's not difficult, really - and you will learn a very useful skill!