For to me unknown reasons - I do not see timing / posting stamps on many of posts so I am late to the party - so be it.
Nor my fault.
Before you get boggled down changing variable types, which are seldom source of real problem, take a look at some of the more complex Examples in IDE. Your code should follow this structure
#include(s) - all used libraries and other #includes
variable declarations - if you want to call them "global variables" that is fine , no reason to argue about it
Setup()
Loop()
your functions declarations
when you attempt to merge two or more "sketches" you can follow same scheme and then you have better idea where you have duplicate code
For example your #include(s) should look like this
#include(s) - all used libraries and other #includes - first sketch
...
#include(s) - all used libraries and other #includes - last sketch
and same in these blocks , hope you get the idea
variable declarations - if you want to call them "global variables" this is fine , no reason to argue about it
Setup()
Loop()
your functions declarations
Of course if you choose just "cut and paste " one sketch after another -- your mileage will vary.