Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Adding sub menu to multiple selection

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";
}
}
//******
0
adinkins
Asked:
adinkins
  • 2
1 Solution
 
bkrahmerCommented:
Hmmm.  Looks like a homework problem to me.  I would think common sense would indicate that making a submenu is really no different than your initial menu.  cin and cout and some new variables ought to work just fine.
brian
0
 
dude1337Commented:
I have done this very thing, I am willing to help, but it does look like a homework problem...bad...

Anyway, have the selection from the first menu goto a function that shows the second menu.  I have a program that does this, if you need help, not complete code.
0
 
adinkinsAuthor Commented:
sure, pass it this way dude.
does it have nested if-else statements because I am having a little problem with them?
0
 
dude1337Commented:
I didn't use nested if-else statements, I find them difficult to work with.  What I did was create a menu that had the user input a choice from the menu list.  Based on the number the put, I had it go through an if-else statement that told the program to go to a different function.  Inside that seperate function I created another menu.

cout << "1.  Menu option....
cin >> menu;

if (menu == 1)
      menua();
else if (menu == 2)
      menub();

Thats the basic program, just put a second menu in the function menua or menub.

If you need anything just ask.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now