You defined the
n
variable twice. The former declaration is superseded by the latter. So, when you try to print its value, this is the second declaration which is taken into account. At this point, it has been declared but remains uninitialized; thus, its value is unpredictable, and can be whatever there is at the address the variable is stored.
You can still refer to the link I provided in my comment:
C++ variable scope[
^]
And, as a general rule, this is a terrible idea to give the same name to several variables in distinct scopes.