SirBernard Posted February 11, 2013 Author Share Posted February 11, 2013 I need help wiht this program.It continues to run even after one of the cases is met.```#include #include #include using namespace std;//Declare functionsfloat gPrismSurface(float lenght, float width, float height);float gPrismVolume(float lenght, float width, float height);float gCylinderSurface(float radius, float height);float gCylinderVolume(float radius, float height);float gSphereSurface(float radius);float gSphereVolume(float radius);//(main) fuction(program))int main(int argc, char *argv[]){ //Declare Variables char sChoice, cChoice; float lenght = 0, width = 0, height = 0, radius = 0; cout << "Solid Selection. Choose From Below\n"; cout << "----------------------------------\n"; cout << "[P]rism [C]ylinder [s]phere\n"; cout << "Entry : "; cin >> sChoice; switch (sChoice) { case 'P': case 'p': cout << "Solid Selection. Prism (Area)\n"; cout << "Cal. Selection.[s]urface [V]olume\n"; cin >> cChoice; switch (cChoice) { case 'S': case 's': { cout << "Cal. Selection.[Surface] Area Cal.\n"; cout << "----------------------------------\n"; cout << "Enter a Length. (Numbers Only!: "; cin >> lenght; cout << "Enter a Width. (Numbers Only!: "; cin >> width; cout << "Enter a Height. (Numbers Only!: "; cin >> height; cout << "---------------Results------------\n"; cout << "Surface Of Prism : " << gPrismSurface(lenght, width, height) << endl; } break; case 'V': case 'v': { cout << "Cal. Selection.[Volume] Area Cal.\n"; cout << "----------------------------------\n"; cout << "Enter a Length. (Numbers Only!: "; cin >> lenght; cout << "Enter a Width. (Numbers Only!: "; cin >> width; cout << "Enter a Height. (Numbers Only!: "; cin >> height; cout << "---------------Results------------\n"; cout << "Volume Of Prism : " << gPrismVolume(lenght, width, height) << endl; } break; } case 'C': case 'c': cout << "Solid Selection. Cylinder (Area)\n"; cout << "Cal. Selection.[s]urface [V]olume\n"; cin >> cChoice; switch (cChoice) { case 'S': case 's': { cout << "Cal. Selection.[Volume] Area Cal.\n"; cout << "----------------------------------\n"; cout << "Enter a Radius. (Numbers Only!: "; cin >> radius; cout << "Enter a Height. (Numbers Only!: "; cin >> height; cout << "---------------Results------------\n"; cout << "Surface Of Prism : " << gCylinderSurface(radius, height) << endl; } break; case 'V': case 'v': { cout << "Cal. Selection.[Volume] Area Cal.\n"; cout << "----------------------------------\n"; cout << "Enter a Radius. (Numbers Only!: "; cin >> radius; cout << "Enter a Height. (Numbers Only!: "; cin >> height; cout << "---------------Results------------\n"; cout << "Volume Of Prism : " << gCylinderVolume(radius, height) << endl; } break; } case 'S': case 's': cout << "Solid Selection. Prism (Area)\n"; cout << "Cal. Selection.[s]urface [V]olume\n"; cin >> cChoice; switch (cChoice) { case 'S': case 's': { cout << "Cal. Selection.[Volume] Area Cal.\n"; cout << "----------------------------------\n"; cout << "Enter a Radius. (Numbers Only!: "; cin >> radius; cout << "---------------Results------------\n"; cout << "Surface Of Prism : " << gSphereSurface(radius) << endl; } break; case 'V': case 'v': { cout << "Cal. Selection.[Volume] Area Cal.\n"; cout << "----------------------------------\n"; cout << "Enter a Radius. (Numbers Only!: "; cin >> radius; cout << "---------------Results------------\n"; cout << "Volume Of Prism : " << gSphereVolume(radius) << endl; } break; } } system("PAUSE"); return EXIT_SUCCESS;}float gPrismSurface(float lenght, float width, float height){ return 2 * (lenght * width) + (width * height) + (lenght * height);}float gPrismVolume (float lenght, float width, float height){ return width * lenght * height;}float gCylinderSurface(float radius, float height){ return 2 * M_PI * pow(radius, 2) + 2 * M_PI * radius * height;}float gCylinderVolume(float radius, float height){ return M_PI * pow(radius, 2) * height;}float gSphereSurface(float radius){ return 4 * M_PI * pow(radius, 2);}float gSphereVolume(float radius){ return (4 / 3)* M_PI * pow(radius, 3);}[/s][/s][/s][/s]``` Link to comment Share on other sites More sharing options...
Godlord Posted February 11, 2013 Share Posted February 11, 2013 That's because you have to break cases explicitly (you forgot to put a break statement at the end of some of your cases).Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
NED Posted February 12, 2013 Share Posted February 12, 2013 He's right.Before :case 'C':case 'c':And before :case 'S':case 's':" break; " is missing. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now