Can't get output to display decimals or last radius

I am doing a project in which I must display the volume for a sphere given the radius 0 thru 4 in increments of 0.2 For some reason I can't figure out why the output wont display the decimals of the whole numbers (1.0,2.0,..) and also why it keeps stopping at 3.8 instead of 4.0.

Thank you for the help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 #include <iostream>
#define Pi 3.1415926
using namespace std;



float SphereVol (float r){
      float vol;
      vol = ((4.0/3.0)*(Pi)*(r*r*r));
      return vol;}
      
int main()
{

float r = 0;
float f = SphereVol(r);
    
while (r <= 4)
{
cout << "Radius: " << r << "  volume: " << SphereVol(r) << endl;    
r = r +(.2);
}

system("pause");
return 0;
}
Last edited on
Topic archived. No new replies allowed.