Please help me to debug this thanks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pedopolio
    New Member
    • Nov 2013
    • 1

    Please help me to debug this thanks

    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    
    struct elevInfo
    {
    	double dimensions;
    	double weight;
    	int persons;
    	char letterans;
    };
    
    void userchoice(char choice);
    double aluminumElevator(double dimension[3]);
    double steelElevator(double dimension[3]);
    double glassElevator(double dimension[3]);
    double capacityWeight(double elevWeight);
    double conversion(double cWeight);
    double person(double& conv);
    
    int main()
    {
    	elevInfo choice, ans;
    
    	cout << "\t\t _______________________________________________" << endl;
    	cout << "\t\t|                                               |" << endl;
    	cout << "\t\t| Welcome to PC4EBER Corp's Elevator Predictor! |" << endl;
    	cout << "\t\t|   Your elevator needs attended by the best.   |" << endl;
    	cout << "\t\t|_______________________________________________|" << endl;
    
    
    	cout << "\n" << endl;
    	do
    	{	cout << "Choose the design of your elevator:" << endl;
    		cout << "[A] Aluminum" << endl;
    		cout << "[B] Stainless Steel" << endl;
    		cout << "[C] Glass" << endl;
    		do
    		{	cout << "Enter letter of your choice: ";
    			cin >> choice.letterans;
    		}while(toupper(choice.letterans) != 'A' && toupper(choice.letterans) != 'A' && toupper(choice.letterans) != 'A');
    
    		userchoice(choice.letterans);
    
    		cout << "\n" << endl;
    	}while(toupper(ans.letterans) == 'Y');
    	
    	getch();
    	return 0;
    }
    
    void userchoice(char choice)
    {
    	elevInfo eWeight, cWeight, convtokg, numpersons, floor;
    	elevInfo dimension[3];
    
    		switch(choice)
    	{	case 'A':
    			cout << "Input desired dimensions of elevator:" << endl;
    			do
    			{	cout << "Width [MINIMUM: 54 in]: ";
    				cin >> dimension[0].dimensions;
    				cin.ignore();
    			}while(dimension[0].dimensions < 54);
    			do
    			{	cout << "Length [MINIMUM: 68 in]: ";
    				cin >> dimension[1].dimensions;
    				cin.ignore();
    			}while(dimension[1].dimensions < 68);
    			do
    			{	cout << "Enter the number of floors in the building: ";
    				cin >> floor.weight;
    				cin.ignore();
    			}while(floor.weight < 2);
    			do
    			{	cout << "Enter the height of a floor [IDEAL: 10-12 ft]: ";
    				cin >> dimension[2].dimensions;
    				cin.ignore();
    			}while(dimension[2].dimensions < 10);
    
    //			eWeight.weight = aluminumElevator(dimension.dimensions);
    			cWeight.weight = capacityWeight(eWeight.weight);
    			convtokg.weight = conversion(cWeight.weight);
    			numpersons.persons = person(convtokg.weight);
    
    			break;
    
    		case 'a':
    		cout << "Input desired dimensions of elevator:" << endl;
    			do
    			{	cout << "Width [MINIMUM: 54 in]: ";
    				cin >> dimension[0].dimensions;
    				cin.ignore();
    			}while(dimension[0].dimensions < 54);
    			do
    			{	cout << "Length [MINIMUM: 68 in]: ";
    				cin >> dimension[1].dimensions;
    				cin.ignore();
    			}while(dimension[1].dimensions < 68);
    			do
    			{	cout << "Enter the number of floors in the building: ";
    				cin >> floor.weight;
    				cin.ignore();
    			}while(floor.weight < 2);
    			do
    			{	cout << "Enter the height of a floor [IDEAL: 10-12 ft]: ";
    				cin >> dimension[2].dimensions;
    				cin.ignore();
    			}while(dimension[2].dimensions < 10);
    
    //			eWeight.weight = aluminumElevator(dimension.dimensions);
    			cWeight.weight = capacityWeight(eWeight.weight);
    			convtokg.weight = conversion(cWeight.weight);
    			numpersons.persons = person(convtokg.weight);
    
    			break;
    
    
    		case 'B':
    			cout << "Input desired dimensions of elevator:" << endl;
    			do
    			{	cout << "Width [MINIMUM: 54 in]: ";
    				cin >> dimension[0].dimensions;
    				cin.ignore();
    			}while(dimension[0].dimensions < 54);
    			do
    			{	cout << "Length [MINIMUM: 68 in]: ";
    				cin >> dimension[1].dimensions;
    				cin.ignore();
    			}while(dimension[1].dimensions < 68);
    			do
    			{	cout << "Enter the number of floors in the building: ";
    				cin >> floor.weight;
    				cin.ignore();
    			}while(floor.weight < 2);
    			do
    			{	cout << "Enter the height of a floor [IDEAL: 10-12 ft]: ";
    				cin >> dimension[2].dimensions;
    				cin.ignore();
    			}while(dimension[2].dimensions < 10);
    
    //			eWeight.weight = steelElevator(dimension.dimensions);
    			cWeight.weight = capacityWeight(eWeight.weight);
    			convtokg.weight = conversion(cWeight.weight);
    			numpersons.persons = person(convtokg.weight);
    
    			break;
    
    		case 'b':
    			cout << "Input desired dimensions of elevator:" << endl;
    			do
    			{	cout << "Width [MINIMUM: 54 in]: ";
    				cin >> dimension[0].dimensions;
    				cin.ignore();
    			}while(dimension[0].dimensions < 54);
    			do
    			{	cout << "Length [MINIMUM: 68 in]: ";
    				cin >> dimension[1].dimensions;
    				cin.ignore();
    			}while(dimension[1].dimensions < 68);
    			do
    			{	cout << "Enter the number of floors in the building: ";
    				cin >> floor.weight;
    				cin.ignore();
    			}while(floor.weight < 2);
    			do
    			{	cout << "Enter the height of a floor [IDEAL: 10-12 ft]: ";
    				cin >> dimension[2].dimensions;
    				cin.ignore();
    			}while(dimension[2].dimensions < 10);
    
    //			eWeight.weight = steelElevator(dimension.dimensions);
    			cWeight.weight = capacityWeight(eWeight.weight);
    			convtokg.weight = conversion(cWeight.weight);
    			numpersons.persons = person(convtokg.weight);
    
    			break;
    
    		case 'C':
    			cout << "Input desired dimensions of elevator:" << endl;
    			do
    			{	cout << "Width [MINIMUM: 54 in]: ";
    				cin >> dimension[0].dimensions;
    				cin.ignore();
    			}while(dimension[0].dimensions < 54);
    			do
    			{	cout << "Length [MINIMUM: 68 in]: ";
    				cin >> dimension[1].dimensions;
    				cin.ignore();
    			}while(dimension[1].dimensions < 68);
    			do
    			{	cout << "Enter the number of floors in the building: ";
    				cin >> floor.weight;
    				cin.ignore();
    			}while(floor.weight < 2);
    			do
    			{	cout << "Enter the height of a floor [IDEAL: 10-12 ft]: ";
    				cin >> dimension[2].dimensions;
    				cin.ignore();
    			}while(dimension[2].dimensions < 10);
    
    // 			eWeight.weight = glassElevator(eWeight.weight);
    			cWeight.weight = capacityWeight(eWeight.weight);
    			convtokg.weight = conversion(cWeight.weight);
    			numpersons.persons = person(convtokg.weight);
    
    			break;
    
    		case 'c':
    			cout << "Input desired dimensions of elevator:" << endl;
    			do
    			{	cout << "Width [MINIMUM: 54 in]: ";
    				cin >> dimension[0].dimensions;
    				cin.ignore();
    			}while(dimension[0].dimensions < 54);
    			do
    			{	cout << "Length [MINIMUM: 68 in]: ";
    				cin >> dimension[1].dimensions;
    				cin.ignore();
    			}while(dimension[1].dimensions < 68);
    			do
    			{	cout << "Enter the number of floors in the building: ";
    				cin >> floor.weight;
    				cin.ignore();
    			}while(floor.weight < 2);
    			do
    			{	cout << "Enter the height of a floor [IDEAL: 10-12 ft]: ";
    				cin >> dimension[2].dimensions;
    				cin.ignore();
    			}while(dimension[2].dimensions < 10);
    
    //			eWeight.weight = glassElevator(dimension.dimensions);
    			cWeight.weight = capacityWeight(eWeight.weight);
    			convtokg.weight = conversion(cWeight.weight);
    			numpersons.persons = person(convtokg.weight);
    
    			break;
    
    		default: cout << " ";
    	}
    }
    
    double aluminumElevator(double dimension[3])
    {
    	return (dimension[0]*dimension[1]*.1*0.101*2) + (dimension[0]*(dimension[3]*12)*.1*.101*2) + ((dimension[3]*12)*dimension[2]*.1*.101*2);
    }
    
    double steelElevator(double dimension[3])
    {
    	return (dimension[0]*dimension[1]*.1*0.101*2) + (dimension[0]*(dimension[3]*12)*.1*.101*2) + ((dimension[3]*12)*dimension[2]*.1*.101*2);
    }
    
    double glassElevator(double dimension[3])
    {
    	return (dimension[0]*dimension[1]*.1*0.101*2) + (dimension[0]*(dimension[3]*12)*.1*.101*2) + ((dimension[3]*12)*dimension[2]*.1*.101*2);
    }
    
    double capacityWeight(double eWeight)
    {
    	return eWeight/.30;
    }
    
    double conversion(double cWeight)
    {
    	return cWeight/2.2046;
    }
    
    double person(double conv)
    {
    	return conv/55;
    }

    HELP ME TO DEBUG THIS PLEASE THANK YOU
    Last edited by Banfa; Nov 26 '13, 10:55 AM. Reason: Please use code tags [code]...[/code]
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Without any description of what this program is supposed to do and what this program actually does (or alternatively a list of compiler errors) this is a hard, verging on impossible task.

    However at line 20 I suspect that

    Code:
    double person(double& conv);
    should be

    Code:
    double person(double conv);
    Last edited by Banfa; Nov 26 '13, 10:59 AM.

    Comment

    • Luuk
      Recognized Expert Top Contributor
      • Mar 2012
      • 1043

      #3
      if you use this:
      Code:
      }while(toupper(choice.letterans) != 'A' && toupper(choice.letterans) != 'A' && toupper(choice.letterans) != 'A');
      than only the choice of 'a' or 'A' is possible.

      and testing for 'A' or 'a' in you case-statement has no purpose...

      If you correct the line i quoted (with the '[CODE]'-tags,
      than you can also delete half of your case-statement.

      (but i'm not a c++ programmer)

      Comment

      Working...