代码工作正常,但问题在于计算。如何将 Cube 函数调用到 SphereVol 函数以便计算正确?
公式 - 如果你想知道 - 球体的体积是 4/3 * 3.1416 * 半径(立方)
#include <iostream>
using namespace std;
const float PI = 3.1416;
float SphereVol(float num);
float Cube(float radius);
void main()
{
float r,
radius;
cout << "Enter a radius: ";
cin >> radius;
r = SphereVol(radius);
cout << "Volume of a sphere with a radius " << radius << " is " << r;
}
float SphereVol(float num)
{
float r;
r = ( ( 4 / 3 ) * PI * Cube(num) );
return r;
}
float Cube(float radius)
{
float num;
num = ( radius * radius * radius );
return num;
}