Amoka Varshan
Amoka Varshan

Reputation: 19

How to fix "too few arguments to function"?

my program is given below

#include <iostream>

using namespace std;

int sum(int x,int y)
{
    return x+y;
}
int sub(int x,int y)
{
    return x-y;
}
int pro(int x,int y)
{
    return x*y;
}
int quo(int x,int y)
{
    return x/y;
}

int main()
{
    int a,b;
    char op;
    cout<<"Enter two numbers:"<<endl;
    cin>>a>>b;
    cout<<"Enter a operator:"<<endl;
    cin>>op;
    switch(op)
    {
    case '+':
        sum(a,b);
        cout<<sum()<<endl;
        break;
    case '-':
        sub(a,b);
        cout<< sub()<<endl;
        break;
    case '*':
        pro(a,b);
        cout<< pro()<<endl;
        break;
    case '/':
        quo(a,b);
        cout<< quo() <<endl;
        break;
    default:
        cout<<"Invalid Operator"<<endl;
    }
    return 0;
}

here is the error i receive

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\amohe\Desktop\cal.cc||In function 'int main()':|
C:\Users\amohe\Desktop\cal.cc|33|error: too few arguments to function 'int sum(int, int)'|
C:\Users\amohe\Desktop\cal.cc|4|note: declared here|
C:\Users\amohe\Desktop\cal.cc|37|error: too few arguments to function 'int sub(int, int)'|
C:\Users\amohe\Desktop\cal.cc|8|note: declared here|
C:\Users\amohe\Desktop\cal.cc|41|error: too few arguments to function 'int pro(int, int)'|
C:\Users\amohe\Desktop\cal.cc|12|note: declared here|
C:\Users\amohe\Desktop\cal.cc|45|error: too few arguments to function 'int quo(int, int)'|
C:\Users\amohe\Desktop\cal.cc|16|note: declared here|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

need solution.

Upvotes: 0

Views: 2840

Answers (1)

Yunnosch
Yunnosch

Reputation: 26703

If you read the quite clear error message, including the line number, then you will notice that it does NOT complain on

    sum(a,b);

But it DOES complain on

    cout<<sum()<<endl;

The difference is rather striking.

You need to give enough parameters to the second one.
Also the first one is useless, compilers tend to tell you that if you increase the warning level.

A solution is to not only calculate and ignore it, instead output it directly and corrctly by using a gentle mixture of your two code lines.

    cout<<sum(a,b)<<endl;

Upvotes: 3

Related Questions