This program is supposed to run through the menus to eventually display the area or volume of a shape depending on the user's menu choices and input. However, it won't run the final menu and I'm not sure why. There aren't any problems when it goes through the debugger, it just doesn't run the whole program. I tried to change my last level switches to if statements but it didn't change anything. Any ideas?
#include <iostream>
using std::cout;
using std::cin;
int main()
{
int menuitem = 0,
areamenuitem = 0,
volumemenuitem = 0,
base = 0,
height = 0,
radius = 0,
rectangle = 0,
circle = 0,
triangle = 0,
cylinder = 0,
sphere = 0;
const float PI = 3.14;
rectangle = 1/2 * base * height;
circle = (radius * radius) * PI;
triangle = 1/2 * base * height;
cylinder = PI * (radius * radius) * height;
sphere = 4/3 * PI * (radius * radius * radius);
cout <<"-- Main Menu --"<<'\n';
cout <<"1. Calculate Area"<<'\n';
cout <<"2. Calculate Volume"<<'\n';
cout <<"Enter Menu Number Choice: ";
cin >> menuitem;
switch ( menuitem )
{
case 1:
cout <<"-- Area Menu --"<<'\n';
cout <<"1. Retangle"<<'\n';
cout <<"2. Circle"<<'\n';
cout <<"3. Right Triangle"<<'\n';
cout <<"Enter Menu Number Choice: ";
cin >> areamenuitem;
break;
switch ( areamenuitem )
{
case 1:
cout <<"--Rectangle--" <<'\n';
cout <<"Enter base: " <<'\n';
cin >> base;
cout <<"Enter height: "<<'\n';
cin >> height;
cout << "Rectangle Area: " << rectangle <<'\n';
break;
case 2:
cout <<"--Circle--"<<'\n';
cout <<"Enter radius: " <<'\n';
cin >> radius;
cout <<"Circle Area: " << circle <<'\n';
break;
case 3:
cout <<"--Right Triangle--" <<'\n';
cout <<"Enter base: " <<'\n';
cin >> base;
cout <<"Enter height: " <<'\n';
cin >> height;
cout <<"Right Triangle Area: " << triangle <<'\n';
break;
default:
cout <<"Error, invalid entry." <<'\n';
}
case 2:
cout <<"-- Volume Menu --"<<'\n';
cout <<"1. Cylinder"<<'\n';
cout <<"2. Sphere"<<'\n';
cout <<"Enter Menu Number Choice: ";
cin >> volumemenuitem;
break;
switch ( volumemenuitem )
{
case 1:
cout <<"--Cylinder Formula--"<<'\n';
cout <<"Enter radius: " <<'\n';
cin >> radius;
cout <<"Enter height: " <<'\n';
cin >> height;
cout <<"Cylinder Volume: " << cylinder << '\n';
break;
case 2:
cout <<"Sphere Formula: 4/3 * pi * radius^3"<<'\n';
cout <<"Enter radius: " <<'\n';
cin >> radius;
cout <<"Sphere Volume: "<< sphere <<'\n';
break;
default:
cout <<"Error, please choose again." <<'\n';
}
}
return 0;
}