Facebook
From Commodious Duck, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 258
  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( 'q' == option ) return 0;
  21.  
  22.         double radius;
  23.  
  24.         switch( option ) {
  25.         case 'r':
  26.             cout << "What is the radius?: ";
  27.             cin >> radius;
  28.             break;
  29.         case 'd':
  30.             {
  31.                 cout << "What is the diameter?: ";
  32.                 double diameter;
  33.                 cin >> diameter;
  34.                 radius = diameter / 2;
  35.             }
  36.             break;
  37.         }
  38.  
  39.         cout << "The volume is: " << sphere_volume( radius ) << endl;
  40.     }
  41. }
  42.  

Replies to Untitled rss

Title Name Language When
Re: Untitled Gamboge Teal cpp 5 Years ago.