Playing around with making calculators and running into a problem with PI

Sep 14, 2013 at 2:06am
Im making a volume calculator and im running into a problem, for some reason no matter what i do the final answer is always "3141.59" so basiclly PI with the decimal point moved over. The code is very long since it contains several other calculators, so ill just show the area of the code that matters to this problem.

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
  


else if (V_choice == "3"){
            
double V_pi = M_PI;
        double V_length = 0.0;
        double V_width = 0.0;
        double V_height = 0.0;
        double V_radius = 0.0;
        double V_final = 0.0;
        double V_pow = 0.0;
        double V_final1 = 0.0;
        string V_choice = "";

            cout <<"Pleas enter the radius: "<<endl;
            cin >> V_radius;
            
            V_pow = pow (V_radius , 3);
            
            V_final1 = (V_pi * V_pow);
            
            cout <<"The volume of the sphere is " << V_final1 <<endl;
            
        }
Sep 14, 2013 at 2:07am
I must point out there are allot of un-used values in there because like i said there are several other calculators with this one.
Sep 14, 2013 at 2:27am
and something im realizing now but a (4/3) belongs before the V_pi, i think i had it in but took it out to play around with.
Sep 14, 2013 at 7:29am
It's just a case of having your formula incorrect. It should be:

V_final1 = (4.0d/3.0d) * pi * pow(V_radius,3);

(4/3 pi r ^ 3)
Last edited on Sep 14, 2013 at 7:30am
Sep 14, 2013 at 4:33pm
thank you very much!... haha, I feel kinda stupid.
Topic archived. No new replies allowed.