C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old May 8th, 2008, 11:08 AM
molemanuk molemanuk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 molemanuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 20 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old May 8th, 2008, 11:34 AM
eatmybinx eatmybinx is offline
Registered User
Click here for more information.
 
Join Date: Apr 2008
Posts: 50 eatmybinx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 31 m 53 sec
Reputation Power: 1
Quote:
Originally Posted by molemanuk

I have tried various other ways of implementing the menus, including switch statements, with little success.

Any help would be much appreciated

Thanks

Sam

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");
with
Code:
cin.get();
or some other form of "pausing"...

Reply With Quote
  #3  
Old May 8th, 2008, 11:58 AM
molemanuk molemanuk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 molemanuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 20 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old May 8th, 2008, 01:51 PM
eatmybinx eatmybinx is offline
Registered User
Click here for more information.
 
Join Date: Apr 2008
Posts: 50 eatmybinx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 31 m 53 sec
Reputation Power: 1
Quote:
Originally Posted by molemanuk
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.

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:
Originally Posted by molemanuk
aslo, how do you post code without it appearing as txt, im used to [cpp]...[/cpp]

thanks again


use CODE tags, with square brackets.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Menu's and linklists...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway