Help on math
Jul 29, 2011 at 8:31am UTC
I'm making this program wich will calculate the volume, surface and areal (2D) af a circle when given a radius. But I'm having some trouble with the code.
This is the function CalcVol:
1 2 3 4 5 6 7 8 9 10 11
#include <cstdlib>
#include <iostream>
using namespace std;
double CalcVol(double ra)
{
double Volume;
Volume = (4/3)*3.14159265*(ra^3);
return Volume;
}
11 C:\Dev-Cpp\CalcVol.cpp invalid operands of types `double' and `int' to binary `operator^'
What can I do?
Jul 29, 2011 at 9:00am UTC
ra^3 means ra XOR 3. Not ra powered to the third. Use instead pow() function from cmath library or simply ra*ra*ra.
Jul 29, 2011 at 9:22am UTC
Thanks, it fixed it!
Topic archived. No new replies allowed.