A function is just reusable code, say for example:
bool is_adult(int age) {
return age > 18;
}
OK, so say you're making a program that needs to check if a user is an adult, you call this function everywhere like:
if (is_adult(23)) {
//Allow access to loads of porn
}
This makes code easier to think about and also easier to fix because my "is\_adult" function is wrong.
It should be "return age >= 0" not just >, because that means you need to be 19 to be an adult, not 18.
Most functions are a bit more complicated than that, but basically it's so you can split up and re-use code so you're not constantly repeating yourself.