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

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.

#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)
{
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;
//******

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;
//*******

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;
//*****

case 5: cout << "Enter the Sphere: ";
cout << "The radius can not be less than zero.\n";
else
{
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
• 2
1 Solution

Commented:
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

Commented:
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

Author Commented:
sure, pass it this way dude.
does it have nested if-else statements because I am having a little problem with them?
0

Commented:
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.