Erika  Yao
Erika Yao

Reputation: 1

error: cannot be used as a function

I just started learning C++ and wrote this :

#include <iostream>
using namespace std;

void sumtype (double sum) {
if (sum>0)
    cout<<"P"<<endl;
else if (sum==0)
    cout<<"0"<<endl;
else
    cout<<"N"<<endl;
}

double sum (double a, double b) {
return a+b;
}

int main() {
char sumtype;
double a;
double b;
cout<<"input value of a: ";
cin>>a;
cout<<"input value of b: ";
cin>>b;
cout<<"sum= "<<sum (a,b)<<endl;
sumtype (sum);

}

However it always says error: 'sumtype' cannot be used as a function sumtype (sum); ^

What's the problem?

Upvotes: 0

Views: 6454

Answers (1)

Ali Kazmi
Ali Kazmi

Reputation: 1458

You have same name for function and variable change variable or function name and it will work. (e.g. char sumtype1;)

Upvotes: 4

Related Questions