Solved

# Adding sub menu to multiple selection

Posted on 2003-02-27

Please explain to me how you would add a submenu to the selection, e.g. if user selects case 1: Right Triangle, they are then again prompted to select

1 - Area, 2 - Perimeter.

Please help.

#include <iostream.h>

#include <cmath>

void main(void)

{

int Choice;

float Radius, Length, Width, Base, Height, Area, Side, Sqrt, Volume, Surface_Area;

//Completed

#define Pi 3.14159

//display selections and request user input

cout << "Welcome to the Shape Information Program\n\n";

cout << "Press the number in parenthesis to calculate information\n";

cout << "regarding one of the following shapes:\n\n";

cout << "(1)\tRight Triangle\n";

cout << "(2)\tEquilateral Triangle\n";

cout << "(3)\tRectangle\n";

cout << "(4)\tCube\n";

cout << "(5)\tSphere\n";

cout << "(6)\tQuit\n\n";

cout << "Enter your choice (1-6): ";

cin >> Choice;

//************

switch (Choice)

{

//completed - just add perimeter

case 1: cout << "Enter the length of the base: ";

cin >> Base;

cout << "Enter the triangle's height: ";

cin >> Height;

if (Base < 0 || Height < 0)

cout << "Only enter positive values.\n";

else

{

Area = Base * Height * 0.5;

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

cout << "The area is " << Area << endl;

}

break;

//******

//****** - E-triangle check formula for C++ input add menu and perimeter

case 2: cout << "Enter the length of one side: ";

cin >> Side;

if (Side < 0 || Side < 0)

cout << "Only enter positive values.\n";

else

{

Area = (Side * Side) * .25 * sqrt(3);

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

cout << "The area is " << Area << endl;

}

break;

//******

//completed - just add perimeter

case 3: cout << "Enter the rectangle's length: ";

cin >> Length;

cout << "Enter the rectangle's width: ";

cin >> Width;

if (Length < 0 || Width < 0)

cout << "Only enter positive values.\n";

else

{

Area = Length * Width;

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

cout << "The area is " << Area << endl;

}

break;

//*******

//******* Check formulas for C++ input add menu

case 4: cout << "Enter the length of a side of the Cube: ";

cin >> Side;

if (Side < 0)

cout << "The Side can not be less than zero.\n";

else

{

Volume = Side * Side * Side;

Surface_Area = 6.0 * (Side * Side);

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

cout << "Volume = " << Volume << endl;

cout << "Surface_Area = " << Surface_Area << endl;

}

break;

//*****

//****** almost complete check formulas for C++ input add menu

case 5: cout << "Enter the Sphere: ";

cin >> Radius;

if (Radius < 0)

cout << "The radius can not be less than zero.\n";

else

{

Volume = (4.0 / 3.0 ) * Pi * Radius * Radius * Radius;

Surface_Area = 4.0 * Pi * Radius * Radius;

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

cout << "Volume = " << Volume << endl;

cout << "Surface_Area = " << Surface_Area << endl;

}

break;

//******

//Completed - all done just do loop before so that user can enter new choice

case 6: cout << "Bye!\n";

break;

default: cout << "You may only enter 1, 2, 3, 4, 5 or 6.\n";

}

}

//******