Thread: Functions

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    Functions

    Based on : Cprogramming.com Tutorial: Functions

    Code:
    #include <iostream>
    
    using namespace std;
    
    int mult ( int x, int y );
    
    int main()
    {
      int x;
      int y;
      
      cout<<"Please input two numbers to be multiplied: ";
      cin>> x >> y;
      cin.ignore();
      cout<<"The product of your two numbers is "<< mult ( x, y ) <<"\n";
      cin.get();
    }
    
    int mult ( int x, int y )
    {
      return x * y;
    }
    Can't understand whats the point of using the int mult ( int x, int y ) instead of

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int x;
      int y;
      
      cout<<"Please input two numbers to be multiplied: ";
      cin>> x >> y;
      cin.ignore();
      cout<<"The product of your two numbers is "<< (x * y) <<"\n";
      cin.get();
    }
    Need some explanation on whats the point of using int mult ( int x , int y ) and hopefully some example on where they use it on. Thanks in advance

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There is no point other than to demonstrate a very simple function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of functions
    By frktons in forum C Programming
    Replies: 29
    Last Post: 06-30-2010, 09:51 AM
  2. Need help with functions
    By jusfry01 in forum C Programming
    Replies: 2
    Last Post: 05-22-2010, 06:25 PM
  3. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  4. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  5. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM