To debug this, add print statements at lines 15 and 23 to show x, y and what else you think you need to see. If you are using a nice IDE you can break on those lines to watch what is going on. While ++x and x++ should be the same in this code, you may occassionally encounter and odd compiler which is why I use the more classic x++, I don't know what compilers and such so it's suspect. You must add debug lines to see what's up.
Also, why the \n on the scanf? Read http://www.cplusplus.com/reference/cstdio/scanf/