### Help Quick with Power Series please

I need to compute a power series and I'm not sure whats wrong!

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` `````` /* Write a funtion which takes an array of coefficients,ai and an integer n, and returns the value of the following equation. Also write a code fragment to show how to call your function. y=a0+a1x+a2x^2+a3x^3+...anx^n */ #include #include using namespace std; // define power function double series(int n, double ai[n], double x); int main(void) { double x; int n; double ai; { cout<<"Please enter a group of numbers"<< endl; cin>>ai[n]; cout<<"enter an x value"<< endl; cin>>x; y=series(ai[n],n,x); } } double series(int n, double ai[], double x) { double y=0; for (int i=n; i>=0;i--) { y=y+ai[i]*pow(x,i); } return y; } ``````
Last edited on
Well, a few things. For one, 'ai' is a variable of type double, not an array of elements 'n'. Two, look at line 28. You have ai[n] and n backwards.
Topic archived. No new replies allowed.