Volume
//a program to calculate Volumes of a cylinder, rectangle and a sphere.
#include<iostream>
using namespace std;
float Volume(float r, float h)
{
return(3.14rrh);//Pi=3.14
}
float Volume(float l, float w, float h)
{
return(lwh);
}
float Volume(float r)
{
return((4/3)3.14rr*r);//Pi=3.14
}
int main()
{
float r, h, l, w;
int num;
do
{
cout<<"\t----Program Menu----\n";
cout<<"\tDesigned by: Peter Kibet Brian\n";
cout<<"\tReg no: s08-6317-2020\n";
cout<<"\tWelcome\n";
cout<<"\n 1. Volume of a cylinder.";
cout<<"\n 2. Volume of a rectangle.";
cout<<"\n 3. Volume of a sphere.";
cout<<"\n 4. Exit the program.";
cout<<"\n\n Please Enter Your Choice: \n";
cin>>num;
switch(num)
{
case 1:
{
cout<<"\n Enter the radius and height of the cylinder: \n";
cin>>r>>h;
cout<<"\n Volume of the cylinder is: \n"<<Volume(r,h);
break;
}
case 2:
{
cout<<"\n Enter the length, width and height of the rectangle: \n";
cin>>l>>w>>h;
cout<<"\n Volume of the rectangle is: \n"<<Volume(l,w,h);
break;
}
case 3:
{
cout<<" \n Enter the radius of the sphere: \n";
cin>>r;
cout<<"\n Volume of the sphere is: \n"<<Volume(r);
break;
}
case 4:
exit(0);
default:
cout<<"\n Invalid choice... Enter numbers 1-4 to continue: \n";
}
}
while(num=4);
return 0;
}