You should avoid using global variables in your programs, instead declare it in a function and pass it by reference into other functions.
The reason for this is once you start making larger programs, any function anywhere in the problem can change it, so if you or a partner decide to change the value of a global variable somewhere in the program and it creates a bug, you would have to sift though 1000s of line of code to find it.
Global variables should only be declared as a constants to avoid this.