Trying to practice with functions before moving on to references, but of course I can't get this program to work. The loops work fine, but my functions aren't connecting with "radius." I know it is a scoping issue, but if anyone can help that would be great.
string response2 = "nothing";
do
{
cout << "Would you like to find the circumference, area, or volume of " << response1 << "? ";
cin >> response2;
} while (response2 != "circumference" && response2 != "area" && response2 != "volume");
if (response1 == "circle" && response2 == "circumference")
{
cout << "Please enter the radius: ";
double radius =0;
cin >> radius;
cout << "The circumference is " << circleCircumference(radius) << endl;
}
if (response1 == "circle" && response2 == "area")
{
cout << "Please enter the radius: ";
double radius = 0;
cin >> radius;
cout << "The area is " << circleArea(radius) <<endl;
}
if (response1 == "circle" && response2 == "volume")
{
cout << "Please enter the radius: ";
double radius = 0;
cin >> radius;
cout << "The volume of the sphere is " << sphereVolume(radius) <<endl;
Please always use code tags. Edit your post, select the code, press the <> button on the formatting menu on the right. It will format it properly and show line numbers.
double volume = (pi^3 * 4 * radius)/3
C++ does not have a ^ exponent operator - you must use the pow function in <cmath>. The formula is wrong as well.
The ^ operator is the bitwise eXclusive OR (XOR), which is entirely different.
Also, I forgot to mention that you have this code 3 times - so shouldn't you get this info earlier (once) and send it to the functions, or make it a function it self?
1 2 3
cout << "Please enter the radius: ";
double radius =0;
cin >> radius;
Always be on the look out for repetitive code - it usually means there is a better way.