In: Computer Science
Write a C++ program for the following problem:
Calculate and print the area and volume of a cone inside a While loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5)
Note: Your loop variable will need to be a double data type
Use two decimal places on all numbers that are double data type.
This will be a table with 3 columns. Don't worry about borders or grid lines on the table.
print column headings outside the loop
Use r as the loop counter and as the radius. Let the height of the cone be twice the radius.
Below the while loop, print the sum of all 3 columns
#include <iostream>
#include <iomanip>   
#include <cmath>
using namespace std;
int main () {
   double r = 1,h,a,v,pi=3.14159;
   cout << fixed << setprecision(2);
      
   cout<<"Radius\tArea\tVolume"<<endl;
   while(r<=20){
      h = 2*r;
      a = pi*r*(r+sqrt(h*h+r*r));
      v = pi*r*r*h/3;
      cout<<r<<"\t"<<a<<"\t"<<v<<endl;
      r += 0.5;
   }
   return 0;
}


