Hi,
Consider that you are writing a book: would you write the whole thing with 1 giant chapter? If you did have chapters, would you write them with one paragraph? And the paragraphs with one giant sentence?
Chapters, paragraphs and sentences are a kind of Divide & Conquer approach, and a type of abstraction: this in turn aids understanding. One should do the same for coding. Understanding is important for design, implementation, and later maintenance of the code: you are not the only one reading or working on the code.
Other things to aid understanding include good meaningful function and variable names. The code should ideally read like a story of what is happening. This can make it self documenting, and comments can be used for other things like the expected range of valid values for a variable, say. Here is a comical reply to one of
Duoas' topics awhile back :+)
http://www.cplusplus.com/forum/lounge/176684/#msg872881
I have that link bookmarked, and have used it a number of times - credit to
Norm Gunderson for writing it :+)
As for how many LOC should be in a function: some give a rough guide of 40 LOC per function, some say even less. As
Duoas says, there is some skill in making a good solution. Candidates for code that could go into a function might include the body of loops or if statements, or rather any compound (block) statement. That is: code between braces {} . I like to have switch statement cases call a function. More obviously is code that might otherwise be repeated.
Sometimes it is worth it to put just a few lines into a function. A great example is a swap function: even if it is only called once, it helps understanding.
Good Luck !!