Answer:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
const double PI = 3.14159;
double height;
double radius;
cout << "Enter the height of the cylinder: ";
cin >> height;
cout << "Enter the radius of the base of the cylinder: ";
cin >> radius;
cout << endl;
cout << "Volume of the cylinder = " << setprecision(4) << PI * pow(radius, 2.0) * height << endl;
cout << "Surface area: " << setprecision(4) << 2 * PI * radius * height + 2 * PI * pow(radius, 2.0) << endl;
cout << endl;
return 0;
}
Explanation:
Code is rearranged so that;
- Variables are defined,
- <em>height</em> and <em>radius</em> of the cylinder is asked from the user,
- The <u>volume</u> and <u>surface area</u> of the cylinder are calculated and printed. (<u>setprecision(4)</u> is used to print two decimal values)