making my code simpler

quick and dirty...

When you create the function you specify the data type that the function will return. For functions that don't return a value, the type is "void" (you will see a lot of this). If you want actual data returned, for example an integer, you would write a function that looks like this (to steal from one of my favorite webcomics):

int randomValue()
{
int r = 4; //chosen by dice roll, guaranteed random
return r;
}

You call this function in your code like this:

int val = randomValue();

Now when you call this function, the value of r (a strictly local variable, only the function that creates it gets to use it) gets passed to val, a variable with more scope (since it is created in the main loop of the code, it can be seen globally).

If you want to pass a value to the function, you need to add an "argument" to the empty parentheses after the function name when you write it:

int randomValue(int a)
{
int r = 4; //chosen by dice roll, guaranteed random
r = r + a;
r = r / 2;
return r;
}

You call THIS version like this:

int val = 8;
int newVal = randomValue(val);

...and voila, randomValue() will take the 8 you sent it, add 4, divide by 2, and return your processed value to the variable newVal.

For a little more detail on functions, try this link http://www2.its.strath.ac.uk/courses/c/section3_9.html
For a lot more detail on functions, read The C Programming Language by Ritchie and Kernighan (sp?). Functions are the essential building blocks for structuring C code, so practice, practice, practice!