need to calculate total volume of the sphere at the end

This is my coding i done..I just stck at the end part where i have to add the total all the value of volume.



#include <iostream>
#include <math.h>
using namespace std;

int main()
{
float r;
float pi= 3.142;
float volume;
float total_volume;

for(r=1; r<=999;r++)
{
cout << "Please insert the value of r from 0-999:";
cin >> r;
volume = (4/3)*(pi)*(r*r*r);
cout<< "Radius:"<< r<< "\t";
cout<<"Volume:"<<volume<<"\n"<<"\n";
}

total_volume += volume;
cout<<"The total volume is:"<<total_volume;

return 0;

}
What are you trying to do?
Write a program to compute and print the volume of a sphere using the formula:
You may use r*r*r to compute r3.
Your program will prompt the user to enter a series of radius readings and the last value read is the
sentinel 999 (i.e. to end input, the user has to type 999 as the last value). After that, it will display the
corresponding volume in a neat format as shown in the output below. Your program should also calculate
the total volume of all the spheres.


this is my question
the use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
float r;
float pi= 3.142;
float volume;
float total_volume;

while(r!=999) {
    cout << "Please insert the value of r from 0-999 (999 to exit): ";
    cin >> r;
    volume = (4/3)*(pi)*(r*r*r);
    cout<< "Radius:"<< r<< "\t";
    cout<<"Volume:"<<volume<<"\n"<<"\n";
    total_volume += volume;
}
cout<<"The total volume is:"<<total_volume


This is the basics, it might change depending on whether or not you include the sphere with the radius in the total calculation.
4/3

In C++, that equals one. Try 4/3.0
Topic archived. No new replies allowed.