A function is a named block of code that performs a specific task. You write the code once, then execute it by calling the function name. main is a function that C++ calls automatically when your program starts.
Functions take inputs called parameters and produce outputs called return values. The main function takes no inputs but returns an integer. Functions let you organize code into logical pieces.
Instead of repeating the same lines, you write them once in a function and call it whenever needed.