Hi James180,
First, please always use code tags - they make it easier to read and have line numbers which we can refer to. So Edit your last post, select all the code, then press the <> button on the right under the format menu. If you do it right it should look like the code in my link below. Some other advice just so you know, is to post any compiler messages in full, they show line numbers & tell us exactly what is going on.
Your problem is a good example of why
NOT to use global variables. If you re-declare a variable in a function (including main() ) then that variable is local to that function - it is not the same variable as the global one.
So move your variable to main(), send variables to which ever function needs them. Either return a value from a function & assign it to a variable in main, or use references.
It might be that the need only be local to a function, that is, not needed elsewhere. In that case local variables are fine, just return the answer.
Have a read of this:
Also the is untold info in the reference section & lots of articles to read.