This project is basically very simple. I think coding
wise looks okay. But when I run it, I always get the
same answer "The object will float".
I took C++ a couple of years ago at avc. Since then occasionally
I practice to refresh my mind. Any body can help, I will be grateful.
Also please let me if I can make the source code look better.
Thanks.
Shervin
/* Buoyancy is the ability of an object to float.
Buoyant force is equal to the weight of the fluid
that is displace by the submerged object.
If force is greater than or equal to Weight of the object,
then it will float, otherwise it will sink.
Write a program that inputs the weight (in pounds) and radius
(in feet) of a sphere and outputs whether sepher will sink or
float in water.
*/
int main()
{
double weight;
double radius;
const double WEIGHT_OF_WATER = 0.624; //Specific weight of water 62.4 lb/ft³
double volume;
double buoyantForce;
const double PI = 0.314;
cout<<"Enter weight of the object: ";
cin>>weight;
cout<<"Enter radius of a sphere: ";
cin >> radius;
volume = (4/3)*(PI * pow(radius, 3)); // volume of the sepher = (4/3)πr³
buoyantForce = weight * volume; //formula to calculate Buoyant force
cout <<"The buoyant force is "<<buoyantForce <<endl;
if(buoyantForce >= weight )
{
cout << "The object will float."<<endl;
}
else
{
cout <<"The object will sink."<<endl;
}