Yeah, the problem is that ^ is not the exponent operator in c++. Rather a^b performs the bit xor operator on the two operands. As the bit xor operator requires two integer types to work (or even to make decent sense) it makes no sense to have it work on floats. Instead you have to find another way to implement exponents. (phorce gave the simplest solution to the ^2 problem, ie a*a)
Labdabeta
Practically a Master Poster
615 posts since Feb 2011
Reputation Points: 27
Solved Threads: 31
Skill Endorsements: 1
31.6, 44.7, both wrong.
Rikkie, your code, once corrected, gives the correct response of 22.36, which is 1/2 what you show above. What did you do?
One other point:
For C++, the math library is <cmath>, not <math.h>
vmanes
Postaholic
2,015 posts since Aug 2007
Reputation Points: 1,283
Solved Threads: 242
Skill Endorsements: 6