Okay, so I have created and array of a maximum degree, which the user defines, and then inputs their own coefficients according to the size of the polynomial. For example, I ask for degree, they type 2, and then input 1,3 and 5 to create a polynomial:
1 + 3x + 5x^2
We have to initialize a function which takes an int and evaluates the expression, the easiest way I have found is using <cmath> and the pow(a,b) function. Below is my code to evaluate, but I keep getting errors. I know I have to convert my "int x" into a double, and then back into an int when I return a value. The function has to remain an int due to the nature of the assignment:
int Poly::evaluate(int x)
{
int total = 0;
double(x);
for(int i = 0; i <= degree; i++){
total += coefs[i]*pow(x,i); //coefs[] array is the array in which the coef's are stored
}
return total;
}