### Homework help 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.

Any hints?

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374`` `````` #include #include using namespace std; int main() { double radius, circumference, circumferenceCone, height, volume,y, x, optimal, maxVolume, hypotenuse, coneRadius, counter, twoPI; const double 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; } `````` I don't necessarily understand the problem, but here's how I rewrote your program.
 ``1234567891011121314151617181920212223`` ``````#include #include #include double const pi = 3.14159, two_pi = 2.0 * pi; int main() { double const cone_length = 10.0; double cone_circumference = 2.0 * pi * cone_length; double const cone_circumference_delta = 0.01; double max_volume = 0.0; for (; cone_circumference > 0.0; cone_circumference -= cone_circumference_delta) { double const cone_radius = cone_circumference / two_pi; double const cone_height = std::sqrt(cone_length*cone_length - cone_radius*cone_radius); double const cone_volume = pi * cone_radius*cone_radius * cone_height / 3.0; max_volume = std::max(max_volume, cone_volume); } std::cout << max_volume; }``````

 The larger entries turn into gibberish.

Give us an example input.
Last edited on ``12345678910111213`` ``````#include #include using namespace std; const double PI = 4.0 * atan( 1.0 ); int main() { double R; cout << "Enter circle radius: "; cin >> R; cout << "Area of circle removed = " << PI * R * R * ( 1.0 - sqrt( 2.0 / 3.0 ) ) << '\n'; cout << "Maximum volume of cone = " << ( 2.0 / 9.0 / sqrt( 3.0 ) )* PI * R * R * R << '\n'; }``````

 ```Enter circle radius: 10 Area of circle removed = 57.6493 Maximum volume of cone = 403.067```

(which coincides with @mbozzi's code's answer).
Last edited on
Registered users can post here. Sign in or register to post.