1,105,386 Community Members

too few arguments in C++ code.

Member Avatar
dellat
Newbie Poster
12 posts since May 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
Please tell me where it goes wrong as the following C++ code gives
the error message: 
**addem.cpp:5: error: too few arguments to function int  addem(int, int)**


`#include <iostream>
using namespace std;

int addem(int, int);

int main()
{
    int x=5;
    int y=2;
    int z;
    z = addem(x+y);
    cout << "The value of z: "<<z;
    system("PAUSE");
    return 0;
}

int addem(int a, int b){
    int c;
    c=a+b;
    return c;
}'


Thank you
Member Avatar
L7Sqr
Veteran Poster
1,006 posts since Feb 2011
Reputation Points: 179 [?]
Q&As Helped to Solve: 168 [?]
Skill Endorsements: 11 [?]
 
1
 

x+y evaluates to a single integral value. You probably intended to write that as: z = addem(x, y);

Member Avatar
Ladis
Newbie Poster
20 posts since Sep 2012
Reputation Points: 10 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
1
 

When youy give x + y separately, the compiler will add the values of x and y.

Here you have used a function to add he values. In this fuction, addem(int , int), it can be called only as z = addem(x ,y); but not as z = addem(x + y)

Member Avatar
dellat
Newbie Poster
12 posts since May 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have understood the mistake. Thank you very much for your help.

Question Answered as of 1 Year Ago by L7Sqr and Ladis
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: