void main()
{
int menu;
do
{
[b]//main menu[/b]
cout<<"Press 1 to create an object of rectangle class.\n";
cout<<"Press 2 to create an object of square class.\n";
cout<<"Press 3 to create an object of ellipse class.\n";
cout<<"Press 4 to create an object of circle class.\n";
cout<<"Press -1 to exit.\n";
cin>>menu;
if(menu ==1)
{
shape * s = new rectangle;
s->input();
int temp;
do
{
[b]//sub menu[/b]
cout<<"Press 1 to display area of rectangle.\n";
cout<<"Press 2 to display perimeter of rectangle.\n";
cout<<"Press 3 to return to main menu.\n";
cin>>temp;
if(temp == 1)
{
s->calc_area();
}
elseif(temp == 2)
{
s->calc_perm();
}
elseif(temp == 3)
{
exit(1);
}
}while(temp!=3);
}
elseif(menu==2)
{
shape * t= new square;
t->input();
int temp;
do
{
cout<<"Press 1 to display area of square.\n";
cout<<"Press 2 to display perimeter of square.\n";
cout<<"Press 3 to return to main menu.\n";
cin>>temp;
if(temp == 1)
{
t->calc_area();
}
elseif(temp == 2)
{
t->calc_perm();
}
elseif(temp == 3)
{
exit(1);
}
}while(temp!=3);
}
elseif(menu==3)
{
shape *p=new ellipse;
p->input();
int temp;
do
{
cout<<"Press 1 to display eccentricity of ellipse.\n";
cout<<"Press 2 to return to main menu.\n";
cin>>temp;
if(temp == 1)
{
p->calc_eccentricity();
}
elseif(temp == 2)
{
exit(1);
}
}while(temp!=3);
}
elseif(menu==4)
{
shape *c=new circle;
c->input();
int temp;
do
{
cout<<"Press 1 to display area of circle.\n";
cout<<"Press 2 to display circumference of circle.\n";
cout<<"Press 3 to return to main menu.\n";
cin>>temp;
if(temp == 1)
{
c->calc_area();
}
elseif(temp == 2)
{
c->calc_circum();
}
elseif(temp == 3)
{
exit(1);
}
}while(temp!=3);
}
}while(menu != -1);
}
Guys!
In this code i when i am in the sub-menu and when i press 3 to go to main menu by using exit(1) function or return function, my program gets end and does not go to main menu. But i want it to go to main menu... Someone help me plz.