I have made a custom function in a header file to get input but I can't figure out how to actually assign to it to the variable as it is returning as garbage value when I print it out. This is a snippet of the code I used.
There is your first mistake. You should not put a function in a header file. They belong in a ".cpp file".
You can put the forward declaration or prototype in a header file and that is fine.
Passing a variable to a function by value just makes a copy of the variable. What you do with this variable in the function is not a problem. You can use it change it, but if you do not return that variable before the closing } it is lost when the function looses scope.
Passing by reference as seeplus has shown you will work to keep the value of "i", needs a better name, when the function ends.
but I can't figure out how to actually assign to it to the variable as it is returning as garbage value when I print it out.
The garbage value is most likely not from the function, but where you first defined "i" and did not initialize it.
For a better understand it would help if you post the whole code that can be compiled and tested. This works better than posting pieces of code that are out of context.
There is no reason why functions can't go in a header file. Mark them as inline and they can be included in multiple compile units with no problems. By some convention, these files would have an extension of .hpp - but the extension of the files can be anything.
#include just includes the code into the source at the point of the #include as if the code from the specified file was actually present there.
Also, #include can be used anywhere in a source file. Although convention is that they are included first (as they usually contain function declarations that are used later), depending upon their contents (which can be any valid code), these can be placed anywhere.
Also, if this is a templated function, then the the declaration can't be in a header file and the definition in another .cpp file. They need to be together in the same included file.