Determines the weight of a steel cylinder by multiplying the volume of the cylinder times its density. - C++ Data Type

C++ examples for Data Type:double

Introduction

The volume of the cylinder is given by the formula:

PI * pow(radius,2) * height

Demo Code

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()/*ww  w. j a  va  2  s. co  m*/
{
   const double PI = 3.1416;
   const double DENSITY = 0.284;
   double radius, height, weight;
   cout << "Enter the radius of the cylinder (in inches): ";
   cin  >> radius;
   cout << "Enter the height of the cylinder (in inches): ";
   cin  >> height;
   weight = DENSITY * PI * pow(radius,2) * height;
   cout << setiosflags(ios:: fixed) << setiosflags(ios::showpoint) << setprecision(4) << "The cylinder weighs " << weight << " pounds" << endl;
   return 0;
}

Result


Related Tutorials