Friday, July 31, 2009

C++ coding errors?

I'm trying to write a program of polynominal evaluation :





#include%26lt;iostream%26gt;





using namespace std;


float x;


float a[3]={1,2,3};


float p(x);





int main(){





cout%26lt;%26lt; p(1)%26lt;%26lt;endl; // error C2064: term does not evaluate to a function taking 1 arguments


return 0;


}





float p(x){ // error C2448: 'p' : function-style initializer appears to be a function definition


float value=a[2];


for(int i=2;i%26gt;=0;i--)


value=value*x+a[i];


return value;


}

C++ coding errors?
You need a type on the variable x in the function definition/declaration.
Reply:In this code:





float x;


float a[3]={1,2,3};


float p(x);





You need to remove:





float p(x);





Then you need to change your function declaration float p(x) to float p(float x).


No comments:

Post a Comment