Use an inline function to calculate Volume: (4.0 / 3.0 * 3.14159 * pow(radius, 3)). - C++ Function

C++ examples for Function:Useful Function

Description

Use an inline function to calculate Volume: (4.0 / 3.0 * 3.14159 * pow(radius, 3)).

Demo Code

#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;
}

Result


Related Tutorials