#include <iostream>
#include <cmath>
usingnamespace 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;
}
Your code is messed up. If you want to let the user enter the size of an array, then you need to allocate it in the heap otherwise the size of an array must be const. Second, double ai; you declared it as a double not an array, so you need to alter it. cin>>ai[n]; ??????
#include <iostream>
#include <cmath>
usingnamespace std;
// define power function
double series(int n, double ai[], double x);
int main(void)
{
double x;
int n;
double *ai;
{
cout<<"Please enter a group of numbers"<< endl;
cin>> n ;
ai = newdouble[n];
cout<<"enter an x value"<< endl;
cin>>x;
y = series(n,ai,x); // <------ y is not declared in this scope?
}
return 0;
}
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;
}
There are a great deal of fundamental errors here. I think you need to reread how to use:
-Declaring variables
-Arrays
-functions
In that order. Then rewrite this program from scratch.
I could address each error in your code blow by blow here, but I think you will find it to be of more benefit to reread the stuff. I suspect there will be other things fundamentally wrong other than what we see here.