Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Question on Proper use of Functions
Please forgive me if my lack of formal programming education is the real trouble, but I see problems being asked on the board now and then where part of the problem states to call a function to do something that I can do as part of one line of code.
If one line of code can be used within main() to determine some result, would it still be "better" or perhaps more "proper" to send out to a function?
As an example, the recent post "coin flip in C++" states "the program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads."
If I write this program with a function called flip, I have to add several lines. If I omit the need for the function flip, I can calculate the answer in one line plus the printf/cout line.
Is the need for a separate function just a part of this class structure at this point in its schedule or is it more proper to perform everything in separate functions? Would I be a problem student in this class?:-)
Comments please. Thanks.
0 · ·