problem with parameters

This is a discussion on problem with parameters within the C++ Programming forums, part of the General Programming Boards category; Hi, In this case, i want to use a double parameter function, but i keep getting an error which says: ...

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

    Question problem with parameters

    Hi,

    In this case, i want to use a double parameter function, but i keep getting an error which says:

    \error: too few arguments to function 'int add(int, int)' \

    And here is the part of code that i`ve written and the compiler says it`s wrong:

    Code:
    int add(int x, int y)
    	{
    	    return x + y;
    
    	}

    by the way i use codeblocks compiler.

    thnx.

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Quote Originally Posted by kasra5004 View Post
    Hi,

    In this case, i want to use a double parameter function, but i keep getting an error which says:

    \error: too few arguments to function 'int add(int, int)' \

    And here is the part of code that i`ve written and the compiler says it`s wrong:

    Code:
    int add(int x, int y)
    	{
    	    return x + y;
    
    	}

    by the way i use codeblocks compiler.

    thnx.
    I think the problem will be when you are calling the function. How are you calling it? It should be in the form of add(int, int). Basically when you call a function the number and type of the arguments needs to match those of the function parameters.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    9
    Hello kasra5004,

    You are receiving this error because in your source code, somewhere you have defined 'add' to accept greater than two arguments when you are only supplying two.. Please make sure that you have defined add, that you have defined it to only hold those two integers. I'd be willing to bet you have defined it elsewhere to accept more than two args.

    Please also make sure that wherever you call the function 'add' that you have supplied it with the proper arguments, such as: cout << "2 + 2 = " << add(2,2);

    Sometimes when passing you accidentally hit the period (.) instead of a comma (,) so the compiler thinks you are only passing a double variable, hence the error.

    -camelCase

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  3. problem in calling DLL
    By bhagwat_maimt in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 10:43 PM
  4. command line parameters problem...
    By ac251404 in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2006, 01:44 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21