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;

}

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.