Goals of exercise are:
- Output the value of PI (3.1419, as per exercise).
- Prompt user to enter radius, r, and store it.
- Calculate surface area of sphere: 4 * PI * r ^ 2
- Calculate volume of sphere: (4/3) * PI * r ^ 3
- Output the surface area and volume of the sphere.
I've been trying to figure this out for a good hour now and am lost. I've also done searching on Google, on DuckDuckGo, on this site's search function, etc.
Here is what I have so far (all constructive criticism welcome):
// pg356_p4.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void userEntry (double& x, double& y);
const double PI = 3.1419;
int main ()
{
double surface;
double volume;
userEntry (surface, volume);
cout << "The surface area of the sphere is: " << surface << endl;
cout << "The volume of the sphere is: " << volume << endl;
system ("pause");
return 0;
}
void userEntry (double& x, double& y)
{
cout << fixed << showpoint;
cout << setprecision(4);
cout << "The value of PI is: " << PI << endl;
double r;
cout << "Please enter a value for the radius: ";
cin >> r;
cout << endl;
double x = 4.0 * 3.1419 * pow (r, 2); // Error provided says: redefinition of "x" and "y"
double y = (4.0/3.0) * 3.1419 * pow (r, 3);
}
Any help is appreciated.