C++ examples for Function:Useful Function
Use an inline function to calculate Volume: (4.0 / 3.0 * 3.14159 * pow(radius, 3)).
#include <iostream> #include <cmath> using namespace std; const double PI{3.14159}; // define global constant PI inline double sphereVolume(const double radius) { return 4.0 / 3.0 * PI * pow(radius, 3); } int main() {//from w w w . ja v a 2s . c om cout << "Enter the length of the radius of your sphere: "; double radiusValue; cin >> radiusValue; // input radius cout << "Volume of sphere with radius " << radiusValue << " is " << sphereVolume(radiusValue) << endl; }