I got this expression: M = 4/3(p*pi*r^3) where p is a constant.
pi is also a constant, and to define it I used M_PI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <cmath>
usingnamespace std;
int main(){
double p, r;
cout<<"Insert p value(Kg/m^3): ";
cin>>p;
cout<<"Insert r value(Kg): ";
cin>>r;
double mass=(4/3)*p*M_PI*pow(r,3);
cout<<"The mass of the esphere is "<<mass<<"Kg"<<endl;
return 0;
}
if I set p and r as 1, it returns 3.14..., it doesn't consider the (4/3)
4 is an integer and 3 is an integer, so that / means integer division. Only one 3 fits in 4, so 4/3 is 1.
If you want the fractional value do (4.0/3.0).