Categories
Programming

C++ Ballon Diameter

Inflate the balloon so that the diameter grows by an inch, and display the amount the volume has grown. Repeat that step: grow the diameter by another inch and show the growth of the volume.

Here is a typical program run:

Diameter: 10
Increase: 173
Increase: 208

Match the formatting of the sample program run in your solution.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
   const double PI = 3.14159265358979323846;   
   double diameter;
   cout << "Diameter: ";
   cin >> diameter;
   double volume1 = PI * diameter * diameter * diameter / 6;
   diameter++;
   double volume2 = PI * diameter * diameter * diameter / 6;
   double growth = volume2 - volume1;
   cout << "Increase: " << setprecision(0) << fixed << growth << endl;
   diameter++;
   double volume3 = PI * diameter * diameter * diameter / 6;
   growth = volume3 - volume2;
   cout << "Increase: " << fixed << growth << endl;
   
   return 0;
}