C++ CODE

Consider the following program in which the statements are in the incorrect order.

Rearrange the statements in the following order so that the program prompts the user to input:

The height of the base of a cylinder
The radius of the base of a cylinder
The program then outputs (in order):

The volume of the cylinder.
The surface area of the cylinder
Format the output to two decimal places.

#include

#include

int main()

{}

double height;

cout << "Volume of the cylinder = "

<< PI * pow(radius, 2.0) * height << endl;

cout << "Enter the height of the cylinder: ";

cin >> radius;

cout << endl;

return 0;

double radius;

cout << "Surface area: "

<< 2 * PI * radius * height + 2 * PI * pow(radius, 2.0)

<< endl;

cout << fixed << showpoint << setprecision(2);

cout << "Enter the radius of the base of the cylinder: ";

cin >> height;

cout << endl;

#include

const double PI = 3.14159;

using namespace std;

Answer :

frknkrtrn

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)

Other Questions