Powers Problem

I need to assign a value 'n' using the equation n=2^k however I'm not sure how to write this in using c++ cause it is not covered with general cmath. I tried using n=pow(2,k) but I am getting an overloading error.
There are 3 versions of pow. One takes floats, one takes doubles, and one takes long doubles.

You're passing two integers. So the compiler doesn't know which of the 3 versions you want to call.

You can fix this by being casting one of your parameters to one of the above types:

 
n = pow(double(2),k);


Or you could make 'k' a double instead of an int.
thank you very much that seemed to work, I'm just having one more problem now and that is I'm trying to use a do-while loop in which the while statement is while (!fabs(tk-tkMinusOne)<=0.000001); however when it comes to the important term it is not terminating and is still looping. The value of tk and tkMinusOne for the function which should make it terminate are:
tk=0.693147
tkMinusOne=0.693148

I ran the debugger and checked the values of the functions and they are what they are supposed to be (with about 30 more unnecessary decimal places). Am I missing something in the while loop statement? Is there a way to limit the doubled values of tk and tkMinusOne?
Topic archived. No new replies allowed.