operator will not divide?

Hello,
Im not sure why but when I run my program using v=4/3*PI*pow(r,3); the output appears to disregard the "4/3", but if I use v=1.333333333*PI*pow?(r,3); it gives me the correct answer. Why is that?


#include <iostream>
#include <iomanip>
#include <math.h>

const double PI = 3.14159;
float volume (float r)
{
double v;
v = 4/3*PI*pow(r,3);
return (v);
}

using namespace std;


int main()
{
float r = 0;

cout.precision(6);
cout.setf(ios::showpoint);
for (r >= 0; r <= 4.2; r+= 0.2)
{
cout << "radius: " << r << " volume: " << volume (r) << endl;
}

return 0;
}
When you divide two integers, the result will also be an integer. So 4/3 results in 1.
If at least one operand is a floating point number, the other one will be automatically converted: 4/3.0
Thanks for the help!
Topic archived. No new replies allowed.