I think it's ur incrementing and decrementing. In the while loop, you do the practically compare p with q then increment them, then that activates your couts within the while loop, causing r to increment. So when you get out the while loop , q would actually be 7, p would be 11 and r would be 8. So when the math is done (it's done in PEMDAS format) it comes out as:
7 + (11/8)
which is:
7 + 1
which results:
8
I think this is how your code is being implemented.