Facebook
From Gamboge Teal, 5 Years ago, written in C++.
This paste is a reply to Untitled from Commodious Duck - view diff
Embed
Download Paste or View Raw
Hits: 242
  1. #define _USE_MATH_DEFINES
  2.  
  3. #include <iostream>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. double sphere_volume( double radius ) {
  9.     return M_PI * 4 / 3 * std::pow( radius, 3 );
  10. }
  11.  
  12. int main() {
  13.     cout << "Welcome User" << endl;
  14.  
  15.     for( ;;) {
  16.         char option;
  17.         cout << "Do you have diameter or ratio? (d/r/q-exit): ";
  18.         cin >> option;
  19.  
  20.         if( 'r' == option ) {
  21.             cout << "What is the radius?: ";
  22.             double radius;
  23.             cin >> radius;
  24.             cout << "The volume is: " << sphere_volume( radius ) << endl;
  25.        
  26.         } else if( 'd' == option ) {
  27.             cout << "What is the diameter?: ";
  28.             double diameter;
  29.             cin >> diameter;
  30.             cout << "The volume is: " << sphere_volume( diameter / 2 ) << endl;
  31.        
  32.         } else if( 'q' == option ) {
  33.             break;
  34.         }
  35.     }
  36. }
  37.