// volume.cpp // // Write a C++ program to ask the user to // input a radius value and a height. // // Calculate (and output) the volume of a cylinder. // // Next, change it to a cone #define PI 3.1415927 #include #include // pow() abs() sin() cos() tan() log() floor() ceil() // round() trunc() sqrt() using namespace std; int main() { double radius, height; double volume_cylinder; cout << "This program calculates the volume of a cylinder\n" << "and a cone.\n\n"; cout << "Enter radius: "; cin >> radius; cout << "Enter height: "; cin >> height; // square the radius: double s = pow( radius, 2 ); // volume_cylinder = PI * radius * radius * height; volume_cylinder = PI * pow( radius, 2 ) * height; cout << "Volume of the cylinder is " << volume_cylinder << endl; double volume_cone; // volume_cone = (1 / 3) * volume_cylinder; // 1 / 3 ==> 0 !!!!! // int / int ==> int (integer division) // // 2 / 3 ==> 0 volume_cone = volume_cylinder / 3; // double / int ==> double / double ==> double cout << "Volume of the cone is " << volume_cone << endl; return 0; }