> but I can’t find an intuitive way of explaining why some functions don’t have to return values
There are lots of other things they could be doing where you don’t necessarily need an output, such as displaying something for the user. I guess in that situation it could still be returning a bool or int to let you know it succeeded or failed, but that’s not always necessary.
> what separates functions from just lines of code?
Technically nothing, but in practice the difference is re-usability. If you’re writing the same lines of code over and over and over you should be putting them in a function. Not only does it keep for file size smaller (which is a big deal in some environments like web development), but then if you have to change that code later you only have to change one place instead of all of them.
Latest Answers