Answer :
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,
- height and radius of the cylinder is asked from the user,
- The volume and surface area of the cylinder are calculated and printed. (setprecision(4) is used to print two decimal values)