Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating and implementing functions (C++).
#8
Functions are like delegating work. The main program is like the big boss telling the underlings "do your thing and give me the final result". The big boss doesn't want to see the underlings' notes or tools, and she definitely doesn't want to look around their desk for the final report. They must hand it to her all nice and clean.

In other words, it's good that all the variables are declared inside the functions. The main program only needs the functions' return values.
If it needs to use them more than once, it may store them in a variable of its own, for example:

Code:
int main()
{
      int count;

- open files etc -

      count = InputCount(inF);
      
      cout << "You entered " << count << " numbers" << endl;

      for (int i = 0;  i < count; i++)
      - do whatever -
}
Reply


Messages In This Thread
Creating and implementing functions (C++). - by SaptaZapta - 2013-09-16, 01:12 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)