?
Solved

Adding sub menu to multiple selection

Posted on 2003-02-27
4
Medium Priority
?
204 Views
Last Modified: 2010-04-01
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
Comment
Question by:adinkins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8038355
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
 

Expert Comment

by:dude1337
ID: 8038731
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 Comment

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

Accepted Solution

by:
dude1337 earned 100 total points
ID: 8061811
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question