Currently in college and working on a problem in my book (it's not actually part of my class, just some thing I want to figure out).
The problem in the book is this,
You've been given the contract for making little conical cups that come with bottled water. These cups are made from a circular waxed paper 4 inches in radius by removing a sector of length x. By closing the remaining part of the circle, a conical cup is made. Your objective is to remove the sector so that the cup is of maximum volume.
Write a program that prompts the user to enter the radius of the circular waxed paper. The program should then output the length of the of the removed sector so that the resulting cup is of maximum volume. Calculate your answer to two decimal places.
It also goes on to say that it should be done using a while loop.
My issue is that I'm pretty much lost, so here is what I've got so far and please keep in mind this is a rough draft..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
const double PI = 3.141592653;
const double WAXED_PAPER_RADIUS = 4.0;
int _tmain(int argc, _TCHAR* argv[])
{
// Variables
double Radius,
Length_Of_Removed_Sector,
Height,
Volume,
Area_Of_Base,
Circumfrance_Of_The_Circle;
// Input
cout << "Input the radius of the paper: "; // Why am I entering the radius if we already know it's 4?
cin >> Radius;
cout << "Input the length of paper to be removed: ";
cin >> Length_Of_Removed_Sector;
// Calculations
Length_Of_Removed_Sector = pow(PI, 2) * Radius * (Radius / 360); // Calculates the length of the removed sector and is very likely wrong
Circumfrance_Of_The_Circle = 2 * Radius * PI; // Calculates the circumfrance of the circle. Circumfrance = 2 * Radius * 3.141592653; this formula is correct
Area_Of_Base = pow(Radius, 2) * PI; // Calculates the area of the circle. Area = Radius^2 * 3.141592653; This formula is correct
Height = sqrt(pow(Radius, 2) - pow(Radius - Length_Of_Removed_Sector / 2 * PI, 2)); // Calculates the hieght but can't be right
// Output
cout << fixed << showpoint << setprecision(2);
cout <<"\n\nThe Radius of the circle is (R): " << Radius << "\n\nThe Radius of the sector that was removed (Y) : " << Length_Of_Removed_Sector << "\n\nThe circumfrance of the waxed paper (C): " << Circumfrance_Of_The_Circle << "\n\nThe height of the circle is (H) : " << Height << endl;
cout << "\nThe area of the base is: " << Area_Of_Base << endl;
return 0;
}
|
So my biggest issue is figuring out exactly how to setup the while loop in the sense that I have no idea what I'm using as a condition to calculate the volume.
1. Do I use the Length_Of_Removed_Sector as a counter that increments each time the loops runs?
2. Do I recalculate the radius of the wax paper and store it in a new variable and use that?
Right now my brain is fried and I just can't figure it out and it's killing me lol.