I am having trouble with the evaluate class. An error message is coming back for the pow(x, degree). I have included the cmath library and have cast x and degree into double. Any hints or tips would be greatly appreciated. I have tested the program without the pow(x, degree) and it works.

int Poly::evaluate(int x){
    int sum=0;
    static_cast<double>(x);
    static_cast<double>(degree);
    for (int i=0; i<degree; i++) {
        sum+=coefs[i]*(pow(x, degree));//here is where I am getting the error
    }
    return sum;

}

Edited 4 Years Ago by mike_2000_17: Fixed formatting

is degree declared elsewhere? Also, you aren't assinging the static cast anywhere. x is still int, and degree is still whatever it is wherever you declared it. You would need

double value = static_cast<double>(x);
double deg = static_cast<double>(degree);

I'm not sure what coefs is an array of (I'm guessing ints) but the pow() function returns a double so you would run into more casting problems there.

I would just use the c-style casting for this problem unless you need to use C++ style type-casting.

sum += coefs[i]*(int)pow((double)x, (double)degree);

Edited 6 Years Ago by sfuo: n/a

This question has already been answered. Start a new discussion instead.