Hi i have a program that calculates volume of shapes, my problem is that after it has calculated the volume, i want it to return to the selection 'menu' to perform the next calculation or exit the programme, any help would be much appreciated.
(i have left the functions out
for ease of reading)
int main (){
bool exit;
exit = true;
do
{
int selection;
cout<<"This application will help you calculate the volume of a shape\nPlease select a shape:\n(1)Cuboide\n(2)Cylinder\n(3)Cone\n(4)Sphere\n(5)Square based pyramid\n";
cin>> selection;
switch (selection)
{
{
case 1://cuboide
double l,b,h;
cout<<"Please enter the length,breadth,and height of the cuboide\n";
cin>>l;
cin>>b;
cin>>h;
cout<<"Volume:"<<cuboide(l,b,h)<<endl;
system("pause");
return 0;
break;
}
{
case 2://cylinder
{
double r,h;
cout<<"Please enter the radius and height of the cylinder\n";
cin>>r;
cin>>h;
cout<<"Volume:"<<cylinder(r,h)<<endl;
system("pause");
return 0;
break;
}
case 3://cone
{
double r,h;
cout<<"Please enter the radius and height of the cone\n";
cin>>r;
cin>>h;
cout<<"Volume:"<<cone(r,h)<<endl;
system("pause");
return 0;
break;
}
case 4://sphere
{
double r;
cout<<"Please enter the radius of the sphere\n";
cin>>r;
cout<<"Volume:"<<sphere(r)<<endl;
system("pause");
return 0;
break;
}
case 5://squarepyramid
{
double b,h;
cout<<"Please enter the base length and height of the pyramid\n";
cin>>b;
cin>>h;
cout<<"Volume:"<<sqrpyramid(b,h)<<endl;
system("pause");
return 0;
break;
}
default:
{
cout<<"Invalid input\n";
system("pause");
return 0;
}
}
my apologies maybe i wasnt clear, i have declared the functions and they work correctly, i just didnt copy they into the post to make it shorter and easier to read, my problem is that i would like the program to repeat this part of the loop
int selection;
cout<<"This application will help you calculate the volume of a shape\nPlease select a shape:\n(1)Cuboide\n(2)Cylinder\n(3)Cone\n(4)Sphere\n(5)Square based pyramid\n";
cin>> selection;
switch (selection)
after it has displayed the volume of the previous shape
int selection;
do
{
cout << "This application will help you calculate the volume of a shape\n""Please select a shape:\n""(1)Cuboide\n""(2)Cylinder\n""(3)Cone\n""(4)Sphere\n""(5)Square based pyramid\n""(6)Exit\n";
cin>> selection;
switch (selection)
{
// switch stuff
}
} while ( selection != 6 );
EDIT: And indeed as @cire pointed out remove return statements within the switch.