My code is work, but I have an issue with the result of my code. when I run with f10 the user is asked to input the value of r3 value and r2 value to calculate both of Volume and Large. with formula :
Volume = 4/3 * pi(3.14) * r^3
Large = 4 * pi(3.14) * r^2
for example : I give 2 value for both of them, then I run it and show the
value of Volume is 24, and
value of Large is 48.
pow function work fine,
r^3 which mean r*r*r, in example 2*2*2 = 8 and r^2 which mean r*r, in example 2*2=4.
BUT, when I count both Volume and Large on scientific calculator the results are different. on Calculator the volume result is 33.493333 and the large result is 50.24
My Question is why the result of calculate in my code is different with the result of calculate on scientific calculator ?
is there something wrong in my code ?
How do I make the same result in my code as calculator's result ?
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 28 29
|
/* Calculate the surface of the sphere radius */
#include<iostream> //cout //cin
#include<math.h> //Pow
using namespace std;
main(void)
{
int a, pi;
a=4/3;
pi=3.14;
float r3, r2, Volume, Large;
cout<<"Calculate the surface of the sphere radius"<<endl;
cout<<"Volume = 4/3 x Pi x r^3"<<endl;
cout<<"Large = 4 x pi x r^2"<<endl;
cout<<"Input r3 value to calculate the Volume = ";cin>>r3;
cout<<"Input r3 value to calculate the Large = ";cin>>r2;
r3 = ("r^3 = %f\n", pow (r3, 3.0));
cout<<"r^3 = "<<r3;
cout<<endl;
Volume = a * pi * r3;
cout<<endl;
r2 = ("r^2 = %f\n", pow (r2, 2.0));
cout<<"r2 = "<<r2;
cout<<endl;
Large = 4 * pi * r2;
cout<<endl;
cout<<"Volume Result = "<<Volume<<endl;
cout<<"Large Result = "<<Large<<endl;
cout<<endl;
}
|