How do I do this? (very new...)

closed account (3CGE8vqX)
Sorry I can't include the code (only have C++ @ school) but there isn't much anyway.

I need to let the user input the radius so the volume of the sphere can be calculated. The volume formula is 4/3πr^3. I'm having problems with how to declare pi (we only learned const float) and I don't know how to raise something to a power (in this case, to the third power)

Can someone please help? Thank you :)
Use std::pow or just multiply the number three times.
You can declare a constant variable, call it pi and initialize it with whatever number you want to approximate pi e.g double const PI = 3.14159;
If you can const float, then you can const double.

There is no operator 'power', but header <cmath> has function 'pow'.

Alternatively: y = x * x * x;
closed account (3CGE8vqX)
THANKS EVERYONE
Also, beware integer division for the 4 / 3 part.
4 / 3 * PI * r * r * r might not give you an expected result.
Topic archived. No new replies allowed.