Question

Volume of hollow sphere given by 4/3 *pi*(Ro^3 –Ri^3 ) where Ro is the outer radius,...

Volume of hollow sphere given by

4/3 *pi*(Ro^3 –Ri^3 )

where Ro is the outer radius, and

Ri is the inner radius

Write a program that prompt user for these two radii, then call a function to calculate volume, and print result. If you enter inner radius larger than outer radius, or negative numbers as radius then warn the user that the radii entered are invalid, and prompt user to reenter radii. Your function calculates the volume of the hollow sphere.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your code..

#include<iostream>
using namespace std;
float volume(float Ro, float Ri)
{  
   float vol,pi = 3.14159;
   float a= ((Ro*Ro*Ro)-(Ri*Ri*Ri));
   vol = (float(4)/float(3)) * pi * a;
   return vol;
}

int main()
{
   float radius1, radius2;
s:   cout<<"Enter radius1(Inner radius) : ";
   cin>>radius1;
   cout<<"Enter radius2(Outer radius) : ";
   cin>>radius2;  
   if((radius1>radius2) || (radius1<0) || (radius2<0))
   {
       cout<<"Entered radius is invaid.Please enter it again"<<endl;
       goto s;
   }
   else
   {
       float v=volume(radius2,radius1);
       cout<<"Volume Of Hollow Sphere is :" << v << endl;
   }
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Volume of hollow sphere given by 4/3 *pi*(Ro^3 –Ri^3 ) where Ro is the outer radius,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT