Basically, you look for the code that's used to calculate the charge and you move that over to the function you're creating. Within that code, you look at the variables that are needed to perform that calculation; those will be the parameters for the function. Then back in the calling function, you replace that code with a function call.

Of course, you also need to be careful about other variables whose values get changed, etc.