Quzah hit the nail right on the head. Also, return statements send output from a function to its caller.
I recommend writing this program as one, big function, before breaking it down into multiple functions.
Quzah hit the nail right on the head. Also, return statements send output from a function to its caller.
I recommend writing this program as one, big function, before breaking it down into multiple functions.
Originally Posted by The Jargon File
Granted there is not much code there so it could be just the mainline program.
However; there is a lot of advantage in breaking larger jobs down to component blocks like the OP did and building explicit functions right from the beginning. If nothing else it compartmentalizes variable and effects on variables making the code easier to debug.
When I write a program I first think about the best way to solve the problem... then I break it down to it's component parts... Get scores, calculate average, convert to letter grade etc. This breakdown is actually the basis for a list of functions that need to be written.
Then when working on each of the parts --functions-- I only need to think about what I'm trying to accomplish at the moment, without worrying about the "big picture" at all. My variables are local and don't affect the mains, so if something messes up I don't have to troubleshoot my entire program, just the misbehaving bit.
The "big blob" concept is fine for simple programs and examples, but when you start writing serious code it more often than not serves to undermine the problem solving effort.