Thread: I have a problem with function...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    I have a problem with function...

    Ok Heres My function program woking
    Code:
    #include<iostream>
    #include<string>
    
    using namespace std;
    
    
    int myfunc();
    
    
    
    
    int main()
    {
        
        myfunc();
     
     
     
        system("PAUSE");
        return 0;
    }
    
    
    
    int myfunc()
    {
        cout << "Function worked" << endl;
        return 0;
    }
    Now That works perfectly But When I try to Get an Int from it...
    Code:
    #include<iostream>
    #include<string>
    
    using namespace std;
    
    
    int myfunc(int myInteger);
    
    
    
    
    int main()
    {
        int = 10;
        myfunc();
     
     
     
        system("PAUSE");
        return 0;
    }
    
    
    
    int myfunc(int x)
    {
        
        cout << "Function worked" << endl;
        return 0;
    }
    Now this doesnt even compile.....It says"Too Few Argument Functions"
    Anyone see the problem?

    By the way im using dev C++.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Are you familiar with the term "argument"? It's what you call the thing you pass to a function when you call it.

    In your case, you have a function called myfunc. It returns an int and takes an int as a parameter. To call that function, you have to pass an int to it, and whatever int you pass will become x inside the function. You didn't pass anything to the function when you called it, so the compiler complained.

    Of course, you don't use x at all, so my guess is that you didn't mean to add the parameter at all. To solve the problem then, just remove the parameter from your function and the prototype.

    If you really wanted that parameter (and just plan to add code to use it later), then you need to pass some value or int variable to the function when you call it.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    13
    Quote Originally Posted by Daved View Post
    Are you familiar with the term "argument"? It's what you call the thing you pass to a function when you call it.

    In your case, you have a function called myfunc. It returns an int and takes an int as a parameter. To call that function, you have to pass an int to it, and whatever int you pass will become x inside the function. You didn't pass anything to the function when you called it, so the compiler complained.

    Of course, you don't use x at all, so my guess is that you didn't mean to add the parameter at all. To solve the problem then, just remove the parameter from your function and the prototype.

    If you really wanted that parameter (and just plan to add code to use it later), then you need to pass some value or int variable to the function when you call it.
    Ahhhh thank you I see what I did.

    Thanks for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2008, 06:33 AM
  2. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 02:36 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM