| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Menu's and linklists...
Hi, My problem is what I hope a relatively easy one to solve:
I am writing a program that deals with shapes and their various aspects. I input shapes (e.g. length and width of a rectangle) into their respective classes and then perform some pointless functions on the linked list.(the joy of learning to program) The problem I am having is with my menu systems. I input the shapes, add them to the list but don’t seem to be able to do anything after that that allows user input. My program just crashes when I try to input any more options. Code as follows Code:
#include <iostream>
#include "rect.h" // includes all the header files
#include "Circle.h"
#include "Cube.h"
#include "Sphere.h"
#include "Triangle.h"
#include "LinkedList.h"
#include "Prism.h"
using namespace std;
const int size = 100;
double temp;
int RecCount=0,CircCount=0,CubeCount=0,SpheCount=0,Tri Count=0,Input,Input2;
bool helper=false,helper2=true;
char stringprot[size];
LinkedList<Shape*> list;
Shape* shape;
Rect RectHolder[size];
Cube CubeHolder[size];
Circle CircleHolder[size];
Sphere SphereHolder[size];
Triangle TriangleHolder[size];
Prism PrismHolder[size];
int tempcounter[size],number,number2;
void menu_2();
void create_menu();
void delete_menu();
void prism_menu();
void main(void){
string error= "\nPlease enter one of the options:" ;
cout << "\n\tWelcome to Sams Super Shape Manipulator & Calculator!!\n\n";
create_menu:
create_menu();
helper=false,helper2=true;
int create_menu_choice;
cin >> create_menu_choice;
while ( helper == false){
helper2 = true;
if (create_menu_choice == 1){
++RecCount;
cout << " \n1. Rect" << endl;
cout << "\nWidth: "; cin >> temp;
RectHolder[RecCount].setWidth(temp);
cout << "Length: "; cin >> temp;
RectHolder[RecCount].setLength(temp);
RectHolder[RecCount].setnumber(RecCount);
RectHolder[RecCount].setname("Rectangle");
}
else if (create_menu_choice == 3){
++CircCount;
cout << " \n3. Circle;" << endl;
cout << "\nRadius: "; cin >> temp;
CircleHolder[CircCount].setRadius(temp);
CircleHolder[CircCount].setnumber(CircCount);
CircleHolder[CircCount].setname("Circle");
}
else if (create_menu_choice == 2){
++CubeCount;
cout << " \n2. Cuboid;" << endl;
cout << "\nWidth: "; cin >> temp;
CubeHolder[CubeCount].setWidth(temp);
cout << "Length: "; cin >> temp;
CubeHolder[CubeCount].setLength(temp);
cout << "height: "; cin >> temp;
CubeHolder[CubeCount].setHeight(temp);
CubeHolder[CubeCount].setnumber(CubeCount);
CubeHolder[CubeCount].setname("Cuboid");
}
else if (create_menu_choice == 4){
++SpheCount;
cout << " \n4. Sphere;" << endl;
cout << "\nRadius: "; cin >> temp;SphereHolder[SpheCount].setRadius(temp);
SphereHolder[SpheCount].setnumber(SpheCount);
SphereHolder[SpheCount].setname("Sphere");
}
else if (create_menu_choice == 5){
++TriCount;
cout << " \n5. Triangle;" << endl;
cout << "\nBase: "; cin >> temp;
TriangleHolder[TriCount].setBase(temp);
cout << "Length: "; cin >> temp;
TriangleHolder[TriCount].setLength(temp);
TriangleHolder[TriCount].setnumber(TriCount);
TriangleHolder[TriCount].setname("Triangle");
}
else if (create_menu_choice == 0){break;}
else{cout << error << endl;}
while( helper2 == true){
cout << "\nWould you like to input another one of these? Yes(1),No(2):" << endl;
cin >> stringprot;
if (isdigit(stringprot[0]) > 0){Input2 = atoi(stringprot);} else Input2 = 0;// Prevents chracter input
if (Input2 == 1){helper = false;helper2 = false;} // Continues looping
else if (Input2 == 2){helper = true;helper2 = false;
goto create_menu;} // Stops the looping and goes to the main menu
else{cout << error << endl;}} // error conditon
}//end while - the one that lets you enter more shapes
for (int i=1; i < RecCount+1; ++i){
shape = &RectHolder[i];
list.AppendNode(shape);}
for (int i=1; i < CubeCount+1; ++i){
shape = &CubeHolder[i];
list.AppendNode(shape);}
for (int i=1; i < CircCount+1; ++i){
shape = &CircleHolder[i];
list.AppendNode(shape);}
for (int i=1; i < TriCount+1; ++i){
shape = &TriangleHolder[i];
list.AppendNode(shape);}
for (int i=1; i < SpheCount+1; ++i){
shape = &SphereHolder[i];
list.AppendNode(shape);}
list.DisplayList();
menu2:
menu_2(); //just a cout function
int menu_option;
if (menu_option == 1){
list.DisplayList();} //this is where my program seems to break!!
//goto menu2;}
//
//if (menu_option == 2){
//goto create_menu;}
}//end create menu
I have tried various other ways of implementing the menus, including switch statements, with little success. Any help would be much appreciated Thanks Sam |
|
#2
|
|||
|
|||
|
Quote:
Code:
...
bool continue = true;
while(continue == true)
{
int Option;
cout << "1. Triangle\n2. Square\n3. Rectangle\n4. Prism\n0. Exit Program\n\n";
cout << "Enter an option: ";
cin >> Option;
switch(Option);
{
case 1:
{ drawTriangle(); system("PAUSE"); break; }
case 2:
{ drawSquare(); system("PAUSE"); break; }
case 3:
{ drawRectangle(); system("PAUSE"); break; }
case 4:
{ drawPrism(); system("PAUSE"); break; }
case 0;
{ continue = false; system("PAUSE); break; }
default:
{ cout << "\nError, invalid choice.\n"; system("PAUSE"); break; }
}
}
...
switch statements are so awesome for menus!!! i love them. may need to replace Code:
system("PAUSE");
Code:
cin.get(); |
|
#3
|
|||
|
|||
|
the problem with that comes when i want to add a triangle then a rectangle or 2 triangles... how do i make it ask me what i want to do again?
also, im inputting stuff into a linked list remember so somewhere in there id need a appendlist() function. aslo, how do you post code without it appearing as txt, im used to [cpp]...[/cpp] thanks again |
|
#4
|
||||
|
||||
|
Quote:
the statements i wrote will continue to loop until the user chooses option 0. so after you make a triangle, the menu will show again and wait for an Option... where you could then choose to make another triangle... maybe inside each draw function, put the appendlist() function call. Quote:
use CODE tags, with square brackets. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Menu's and linklists... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|