Advertisement
invention8

Volume of a Cylinder

Mar 6th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1.  
  2. // Created by Tan
  3. // Program designed to output volume of a cylinder.
  4. // User is asked for value of Radius and Height, then Volume is output.
  5. // Formula used: V= pi*r^2*h
  6. // Pi = 3.14159265
  7.  
  8. #include <iostream> // Needed for Cin Cout
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     double d_Volume, d_Pi, d_Radius, d_Height; // Names of variables in our equations. Added a prefix of " d_ " to improve syntax highlighting.
  15.     cout << "+++++++++++++++++++++++++++++++++++++++" << endl;
  16.     cout << "Cylinder Volume Calculator by Tan" << endl;
  17.     cout << "Input the radius and height of the cylinder whose volume you'd like calculated." << endl;
  18.     cout << "Formula used: Volume = Pi*Radius^2*Height" << endl;
  19.     cout << "Value of Pi is to 9 figures." << endl;
  20.     cout << "+++++++++++++++++++++++++++++++++++++++" << endl;
  21.  
  22.     cout << "What is the radius of your cylinder?" << endl;
  23.     cin >> d_Radius; // Radius is stored as a number
  24.  
  25.     cout << "What is the height of your cylinder?" << endl;
  26.     cin >> d_Height; // Height is stored as a number
  27.  
  28.     d_Pi = 3.14159265;
  29.  
  30.     d_Volume = d_Pi*pow(d_Radius, 2) * d_Height;
  31.  
  32.     cout << "The volume of your cylinder is: " << d_Volume << endl;
  33.  
  34.     system("pause");
  35.     return 0;
  36. }
  37.  
  38. // Variables
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement