+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    120
    Points
    403,586.69
    Rep Power
    177

    Default (C++) Calling Functions

    Tut by TheEliteOne

    Calling Functions in C++

    Lets say we want a title, like this:

    TheEliteOne's Example!
    at the top of the screen, but we don't want to type in cout<<"TheEliteOne's Example!\n\n"; every time. We can use a function and call it every time we want to. Like this:

    Code:
    #include <iostream.h>
    void title()
    {
    	cout<<"TheEliteOne's Example!\n\n";
    }
    void pause()
    {
    	system("pause");
    }
    void cls()
    {
    	system("cls");
    }
    int main()
    {
        First:
              cls(); //Calls are cls function.
    	  title(); //Calls are title function.
    	  cout<<"See.. not that hard right?\n\n";
    	  pause(); //Calls are pause function.
    	  goto First;
    }
    I don't know about but I would rather type in some thing like "title();" than "cout<<TITLE OF YOUR PROGRAM\n\n"; " every time I wanted to ;) hope it helped.

  2. #2
    Join Date
    Jan 2008
    Location
    PA
    Posts
    1,164
    Points
    1,947,926.25
    Rep Power
    207

    Default Re: (C++) Calling Functions

    Not bad, ill add to it:
    The main purpose of methods is to shorten code so if a block of code keeps appearing in your program create a method for it and just call the method as needed. Also in OOP they are used for accessing/manipulating data in an object.


    Get Vip: »Here«
    Donate: »Here«
    >>List of Compilers<<
    >>SFDM Name Generator<<
    [Owner Of FluidCoding]

  3. #3
    Join Date
    Oct 2009
    Posts
    120
    Points
    403,586.69
    Rep Power
    177

    Default Re: (C++) Calling Functions

    Cool, thanks.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts