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;
    return 0;

int addem(int a, int b){
    int c;
    return c;

Thank you

Recommended Answers

All 3 Replies

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

Member Avatar

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)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.