• 0

Power Function Error !


Question

Hi,

I am using a power funtion in my program and i am getting errors and apparently my program is not accepting the changes.

I am using the 'pow' function. the formulas i am writing are - Diameter = B Volume 1/3 and Pressure = Volume 1/ B

and i am using #include <cmath>

/**************************************************

** Diameter

***************************************************/

float balloon::diameter()

{

return (B * (float) pow(Volume,(1/3))); // Calculating Diameter

}

/*******************************************************

** Pressure

******************************************************/

float balloon::pressure()

{

return ((float) pow(Volume,(1/B))); // Caluclating Pressure

}

the errors i am getting with this is -

\visual studio 2008\projects\prog8\code_2.cpp(71) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data

\visual studio 2008\projects\prog8\code_2.cpp(81) : error C2666: 'pow' : 6 overloads have similar conversions

c:\program files\microsoft visual studio 9.0\vc\include\math.h(575): could be 'long double pow(long double,int)'

c:\program files\microsoft visual studio 9.0\vc\include\math.h(573): or 'long double pow(long double,long double)'

1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(527): or 'float pow(float,int)'

1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(525): or 'float pow(float,float)'

1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(489): or 'double pow(double,int)'

1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(123): or 'double pow(double,double)'

1> while trying to match the argument list '(float, double)'

1>Build log was saved at "file://c:\Users\Aman\Documents\Visual Studio 2008\Projects\Prog8\Debug\BuildLog.htm"

1>Prog8 - 1 error(s), 1 warning(s)

Would appreciate any help...

Thanks

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I think all you need to do is to cast the values you're passing to pow. The error is stating that it has multiple versions of the pow function that takes different argument types and it doesn't know which one you want it to use.

Link to comment
Share on other sites

  • 0
I think all you need to do is to cast the values you're passing to pow. The error is stating that it has multiple versions of the pow function that takes different argument types and it doesn't know which one you want it to use.

Well i did do that , and got the value correct for one of them ... but i am have trouble with this one

float balloon::diameter()

{

return B *( float pow(float Volume,float (1/3)) ); // Calculating Diameter

}

the formula here is -

B air 1/3

don't know where i am wrong

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.