I am supposed to write a program that prompts the user to enter the radius of a circle then removes small increments of the circle so it forms a cone and then calculates the volumes of the cone till you get the maximum volume of the cone then output the max volume of the cone and the size of the total piece removed.
This is my third wack at this and this is what I have so far but it's still not right. The larger entries turn into gibberish.
#include <iostream>
#include <cmath>
usingnamespace std;
int main() {
double radius, circumference, circumferenceCone, height, volume,y, x, optimal, maxVolume, hypotenuse, coneRadius, counter, twoPI;
constdouble pi = 3.141592654;
cout << "Input radius of the circular waxed papaer :";
cin >> radius;
hypotenuse = radius;
twoPI = pi * 2;
circumference = 2 * pi * radius;
x = 0.09;
counter = 0;
maxVolume = 0;
optimal = 345.5751919;
circumferenceCone = circumference;
do
{
maxVolume = volume; //hold the value from the previous loop
y = optimal - circumferenceCone; // gets the circumference from of the piece removed.
circumferenceCone = circumferenceCone - x; // removes x of the circle
coneRadius = circumferenceCone / twoPI; // calulates the radius of the mouth of the cone
height =(hypotenuse * hypotenuse) - (coneRadius * coneRadius); //calculates the height of the cone
height = sqrt(height); // completes the height calculation
volume= (pi * height * coneRadius * coneRadius)/3; // calulates the volume of the cone
// cout <<"lth "<< optimal - circumferenceCone<<" conecir "<< circumferenceCone <<" conerad "<< coneRadius <<" x "<< x<<" height "<< height <<" vol "<< volume<< endl // used to trouble shoot
x= x +.09;
counter++;
}
// while (counter < 100); // used to troubleshoot
while (maxVolume < volume); // if the maxVolume is less than the new volume loop continues till false
cout << y<< endl;
cout << maxVolume << endl;
return 0;
}