#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
double sphereVolume;
double sphereRadius;
cin >> sphereRadius;
sphereRadius = sphereVolume;
sphereVolume = (4.0 / 3.0) M_PI * 3 * 3 * 3;
cout << fixed << setprecision(2) << sphereVolume << endl;
return 0;
}
Please Tell us what’s happening in your own words.
Learning to describe problems is hard, but it is an important part of learning how to code.
Also, the more you say, the more we can help!
when I enter radius as 1.0 I get the wrong output number
You never use the sphereRadius variable.
Your radius is hardcoded as “3” which is why this outputs the volume for 3 no matter what input that you use.
volume = (4/3) × π × r³
Okay here’s some information can help us help you to the best of your abilities.
- What are you trying to accomplish?
- What have you tried so far?
- What is the program currently doing?
- What do you expect the program to be doing?