Develop a program that will output the volume V of a sphere for a given radius R. The program user inputs the initial, incremental, and ending values of the radius. For each value of the radius, the program will calculate the corresponding volume V = 4πR3/3 and will print the radius and the volume. Use SI units.
(Hint: if the loop starts at 10.2 mm and the incremental value is 2.5 mm the program should display a series of lines like this:
The volume of a sphere with a radius of 10.2 mm is … mm3
The volume of a sphere with a radius of 12.7 mm is … mm3
...)
My current program looks like this:
Code
#include <iostream>
#include <cmath>
using namespace std;
int main(){
//Input radius, volume, initialValue, increment, ending Value,
double x, volume, initialRadius, increment, endingRadius, radius;
#define PI 3.14159
//Processing
//Output Volume of Sphere, Radius,
cout<<" Please input the initial radius of the sphere: "<<endl;
cin>>initialRadius;
cout<<"Please input your increment value: "<<endl;
cin>>increment;
cout<<"Please input the final radius of the sphere."<<endl;
cin>>endingRadius;
for (x=initialRadius;x<=endingRadius; x=increment)
volume=4*PI*pow(radius,3)/3.0;
cout<<"The Volume of a sphere with a radius of "<<radius<<" mm is "<<volume<<" mm3."<<endl;
cin.get();
return 0;
}
How can I make it so that my radius variable changes to the new radius everytime?