Need some Help with a code

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
WesFox13
Padawan Learner
Posts: 274
Joined: 2007-02-14 11:50am
Location: Sammamish, WA, USA
Contact:

Need some Help with a code

Post by WesFox13 »

Hey Can someone here who's good with C++ Help me out here? I need a bit of help doing this assignment for my class.

I'm supposed to make a program that will do 3 things with a menu

the first option is supposed to make a table of different lumber sizes (From 2 by 2 inches to 10 by 12 inches. The height increasing by 2's to 12 and then starting over again only with the next base number 2, to 4 to 6 to 8 to 10) along with their Cross Sectional Area, Moment of Inertia, and Section Modulus.

The Second Part is to do the computations of those only with custom mumbers.

The third seclection relates to the Moment of Inertia where the user has to input a Moment of inertia and a base and it should compute a height to match that base and Moment of Inertia.

for the second and third ones I also have to confirm that the user inputs only positive numbers and decimals. I also have to keep the numbers to about 3 decimal places.

The things I need help with are:
1. how to make the table in the program
2. How to make the menu visable because every time I ran it the menu doesn't show up.

My Code:

Code: Select all

///
///
///
/// Lumber Conversion
/// By: Wesley Montgomery
/// Date: 
/// This program calculates the crosssectional area, the moment of inertia, and the sectional modulus of
/// a piece of wood.
///
///
///

#include <iostream>
#include <iomanip>

using namespace std;
int main () 
{ 
	  int  lumbersizes, crosssectionarea, inertia, sectionmod, base, height, thirdheight;
	  bool done; //exit flag
	  char selection; //menu selection
	   done = false;

	   while (!done); 
	   {
		 // Output menu list
		 cout << "\n\n";
		 cout << "************************\n\n";		
		 cout << "  Lumber Pack: \n";		
		 cout << "  1) Lumber Size Chart\n";		
		 cout << "  2) Custom base and Height Values chart\n";		
		 cout << "  3) Moment of Inertia\n";		
		 cout << "  4) Exit Program\n\n";		
		 cout << "************************\n\n";		

		// Input data					
		cout << "Menu selection -> ";		
		cin >> selection;
		cout << "\n\n";

		//Process Input
		 if (selection=='1')
		 {
			 cout << "Under Construction." << endl;

         } else if (selection=='2')
		   {  
			  cout << "Enter Base of Lumber:" << endl;
			  cin >> base;
			  cout << "Enter Height of Lumber:" << endl;
			  cin >> height; 
			  cout << "Cross sectional Area:" << endl;
			  crosssectionarea = base * height;
			  cout << crosssectionarea << endl;
			  cout << "Moment of Inertia:" << endl;
			  inertia = (base*(height*height*height))/12;
			  cout <<  inertia << endl;
			  cout << "Section Modulus:" << endl;
			  sectionmod = (base*(height*height))/6;
			  cout << sectionmod << endl;
		  }
		else if (selection=='3')
		 {
			cout << "Moment of Inertia\n\n";
			cout << "Enter the Moment of Inertia and the base of the piece of lumber to try to match it:";
			cout << "\n Moment of Inertia = ";
			cin >> inertia;
			cout << " Base = ";
			cin >> base;
		   thirdheight = base*inertia / 12;
			cout << "height:";
			cout << thirdheight;
			}
		else if (selection=='4')
		  {
			cout << "Goodbye.\n\n";
			done = true;					// flag for exit
		  }else
		  {
			 cout << "** Invalid Selection. **\n\n";
		  }

		}// end of while loop

}

///End of Program
My Political Compass:
Economic Left/Right: -5.25
Social Libertarian/Authoritarian: -5.90

Designation: Libertarian Left (Social Democrat/Democratic Socialist)
Alignment: Chaotic-Good
User avatar
EnsGabe
Youngling
Posts: 54
Joined: 2006-07-10 09:49pm

Re: Need some Help with a code

Post by EnsGabe »

Code: Select all

while (!done);  <----
{
    ...
}// end of while loop

///End of Program
That semicolon shouldn't be there. You've got an infinite loop that just checks the boolean value.
The Monarch: "Anyone wanna explain to me why my coccoon is charred?"
24: "Because you told us to blow it up"
The Monarch: "And why it is sideways?"
21: "We were following orders! You can't yell at us for following orders."
24: "Or kill us for following orders."
User avatar
Darth Paul
Sith Apprentice
Posts: 52
Joined: 2002-08-22 11:44pm
Location: Canada

Post by Darth Paul »

Did you run this through the debugger? You have a classic typo:

Code: Select all

while (!done); 
I'm not totally sure what you meant for the table, but something like this came to mind:

Code: Select all

void DoTable()
{
	cout << "Size\t\tX-Section\tMoment/Inertia\tModulus\n";

	for (int w = 2; w < 12; w+= 2 )
	{
		for (int h=2; h<10; h+=2 )
		{
			// the 3 calculations are just made up here - make a function for each one...
			cout << w << "x" << h << "\t\t" << w * h << "\t\t" << w * h * 2 << "\t\t" << w * h * 3 << "\n";
		}
	}
}
Edit: I type too slow :)
Post Reply