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.
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.
In C++, please use visual studios and post the output
#include <iostream> using namespace std; #define PI 3.14159 int main() { cout << "Radius\tHeight\tVolume" << endl; double r = 1, h, v, rTotal = 0, hTotal = 0, vTotal = 0; while (r <= 20) { h = 2*r; v = PI * r *r * h/3; rTotal += r; vTotal += v; hTotal += h; cout << r << "\t\t" << h << "\t\t" << v << endl; r += 0.5; } cout << rTotal << "\t\t" << hTotal << "\t\t" << vTotal << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.