10 Replies - 482 Views - Last Post: 06 October 2012 - 08:25 PM Rate Topic: -----

#1 CellulaS  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 19-June 12

Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 05:43 AM

Hello Guys I Wanna Know How Do I Optimize My Code ??? im trying to make fast food billing and im kinda stuck on how do i optimize or make few less code i just wanna know how do i optimize option 2? is there a way without using switch or do i have to use switch in this option 2 ?


#include <iostream>
#include <conio.h>
#include <string.h>
#include <iomanip.h>
#include <time.h>

#define Plain Egg 15.45;

using namespace std;

void do_again(),direction(int ans);
void option_1(),option_2(),option_3(),option_4(),option_5(),option_6();

int main()
{
     do_again();

     return 0;
}




void do_again()
{
     int ans;
     do
     {
          cout << "Welcome\n";
          cout << "1: Combo Meal\n";
          cout << "2: Single Meal\n";
          cout << "3: \n";
          cout << "4: \n";
          cout << "5: \n";
          cout << "6: Option 6 - Exit\n";
               cin  >> ans;
               cin.ignore(80,'\n'); 
          direction(ans);
     }while(ans!=6);
}

void direction(int ans)
{
     switch (ans)
     {
          case 1: 
                      
               option_1();
               break;
          case 2:
               option_2();
               break;
          case 3:
               option_3();
               break;
          case 4:
               option_4();
               break;
          case 5:
               option_5();
               break;
          case 6:
               option_6();
               break;
          default:
               cout << "";/
               break;
     }
}



void option_1()
{
}

void option_2()
{
  int ch2;
  	cout <<" !! Enjoy your Food !!!\n";
	cout <<"Please Select Your Order\n";
	cout <<"\n";

	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"|   MENU LIST                                                                |\n";
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 1 - Plain Egg" << setw(18) << "P15.45" <<" |" <<setw(26) <<"11 - Jolly Hotdog" <<setw (17) <<"P45.75 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 2 - Bacon and Egg" << setw(14) << "P34.75" << setw(30) <<"12 - BeefChicken" <<setw(15) <<"P61.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 3 - ChickenJoy" << setw(17) << "P89.75" << setw(25) <<"13 - Spaghetti" <<setw(20) <<"P49.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 4 - French Fries" << setw(15) << "P25.50" << setw(25) <<"14 - Mango Pie" <<setw(20) <<"P24.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 5 - Coke Float" << setw(17) << "P35.50" << setw(25) <<"15 - Beef Stew" <<setw(20) <<"P72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 6 - Coke (Large)" << setw(15) << "P25.15" << setw(29) <<"16 - Fish Fillet" <<setw(16) <<"P72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 7 - Swirly Bitz" << setw(16) << "P28.50" << setw(31) <<"17 - Breakfast Steak" <<setw (14) <<"P52.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 8 - Burger" << setw(21) << "P35.75" << setw(27) <<"18 - Corned Beef" <<setw(18) <<"P65.00 |" << endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 9 - Rice" << setw(23) <<"P15.50" << setw(26) <<"19 - Longganisa" <<setw(19) <<"P55.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 10 - Coffee" << setw(20) <<"P15.00" << setw(31) <<"20 - Chicken Sausage" <<setw(14) <<"P50.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
    cin >> ch2;

    switch(ch2) {
        case 1:
          
            break;
        case 2:
           
            break;
        case 3: {
          
        
            break;
        }
        case 4:
           
            break;
        case 5:
           
            break;
        case 6:
          
            break;
        case 7:
          
            break;
        case 8:
            return;
            
        case 9:
            return;
            
        case 10:
            return;   
        
        case 11:
            return;
            
        case 12:
            return;  
        case 13:
            return; 
        case 14:
            return; 
        case 15:
            return; 
        case 16:
            return; 
        case 17:
            return; 
        case 18:
            return; 
        case 19:
            return; 
        case 20:
            return; 
      
        default:
                
            cout << "\a";
    }

		
}

void option_3()
{
}

void option_4()
{
}

void option_5()
{
}
void option_6()
{
}


This post has been edited by CellulaS: 06 October 2012 - 05:52 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Got A Question How Do I Optimize My Code?

#2 shurd  Icon User is offline

  • D.I.C Head

Reputation: 37
  • View blog
  • Posts: 162
  • Joined: 05-February 12

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 06:05 AM

Well you could break your menu into another function, as well as your switch. And you could use a file/database to hold the products and it's values.
Was This Post Helpful? 1
  • +
  • -

#3 CellulaS  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 19-June 12

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 06:16 AM

Hey shurd Thanks but I dont really know how to hold file or database yet could you give me an example ? on what to do on the database ? thingy ? I was wondering is there another way without using database im just new on database..

This post has been edited by CellulaS: 06 October 2012 - 06:19 AM

Was This Post Helpful? 0
  • +
  • -

#4 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1707
  • View blog
  • Posts: 3,275
  • Joined: 30-May 10

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 07:20 AM

See what you can do with this snippet.

struct menuitem {
    string item;
    double price;
} menu[] = {
    { "Plain Egg", 15.45 },
    { "Jolly Hotdog", 45.75 },
    { "Bacon and Egg", 34.75 },
    // and so on
};
int menuLength = sizeof(menu)/sizeof(menu[0]);
for ( int i = 0 ; i < menuLength ; i++ ) {
    cout << (i+1) << " - " << menu[i].item << " " << menu[i].price << endl;
}



Was This Post Helpful? 2
  • +
  • -

#5 CellulaS  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 19-June 12

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 08:18 AM

Thanks Salem_c Was wondering do you have any example for database i was curious what are the step in using and are there any method at it ?
Was This Post Helpful? 0
  • +
  • -

#6 CellulaS  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 19-June 12

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 09:21 AM

Hello Everyone I was wondering how can i add another menu from my other menu so basically
it goes like this

Hello !

1. Combo Meals
2. Single Meals
3. exit

i have been trying to figure how to use both int,float function and void function

#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <iomanip.h>
#include <time.h>

using namespace std;


const std::string currentDateTime() {

    time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    tstruct = *localtime(&now);
  
    strftime(buf, sizeof(buf), "%m / %d / %y - %I: %M: %S %p", &tstruct);

    return buf;
}



struct menuItemType

{
	
	string name;
	double price;

};


	double tax, total = 0;

	int getData(menuItemType menuList[20]);
	int showMenu(menuItemType menuList[20]);
	int printCheck(menuItemType menuList[20]);

	int main()
{
	menuItemType menuList[20];

	getData(menuList);
	showMenu(menuList);
	printCheck(menuList);

	return 0;
}

int getData(menuItemType menuList[20])
{

	menuList[0].name = "Plain Egg";
	menuList[0].price = 15.45;
	menuList[1].name = "Bacon and Egg";
	menuList[1].price = 34.75;
	menuList[2].name = "ChickenJoy";
	menuList[2].price = 89.75;
	menuList[3].name = "French Fries";
	menuList[3].price = 25.50;
	menuList[4].name = "Coke Float";
	menuList[4].price = 35.50;
	menuList[5].name = "Coke (Large)";
	menuList[5].price = 25.15;
	menuList[6].name = "Swirly Bitz";
	menuList[6].price = 28.50;
	menuList[7].name = "Burger";
	menuList[7].price = 35.75;
	menuList[8].name = "Rice";
	menuList[8].price = 15.55;
	menuList[9].name = "Coffee";
	menuList[9].price = 15.00;
	menuList[10].name = "Jolly Hotdog";
	menuList[10].price = 45.75;
	menuList[11].name = "Ice Cream";
	menuList[11].price = 61.00;
	menuList[12].name = "Spaghetti";
	menuList[12].price = 49.00;
	menuList[13].name = "mango Pie";
	menuList[13].price = 24.50;
	menuList[14].name = "Beef Stew";
	menuList[14].price = 72.00;
	menuList[15].name = "Crispy Bangus";
	menuList[15].price = 72.00;
	menuList[16].name = "Breakfast Steak";
	menuList[16].price = 52.50;
	menuList[17].name = "Corned Beef";
	menuList[17].price = 65.00;
	menuList[18].name = "Longganisa";
	menuList[18].price = 55.50;
	menuList[19].name = "Chicken Sausage";
	menuList[19].price = 50.50;

}

int showMenu(menuItemType menuList[20])
{

	cout <<"!! Enjoy your Food !!!\n";
	cout <<"Please Select Your Order\n";
	cout <<"\n";

	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"|   MENU LIST                                                                |\n";
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 1 - Plain Egg" << setw(18) << "15.45" <<" |" <<setw(26) <<"11 - Jolly Hotdog" <<setw (17) <<"45.75 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 2 - Bacon and Egg" << setw(14) << "34.75" << setw(30) <<"12 - Palabok Fiesta" <<setw(15) <<"61.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 3 - ChickenJoy" << setw(17) << "89.75" << setw(25) <<"13 - Spaghetti" <<setw(20) <<"49.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 4 - French Fries" << setw(15) << "25.50" << setw(25) <<"14 - Ice Cream" <<setw(20) <<"24.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 5 - Coke Float" << setw(17) << "35.50" << setw(25) <<"15 - Beef Stew" <<setw(20) <<"72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 6 - Coke (Large)" << setw(15) << "25.15" << setw(29) <<"16 - Crispy Chicken" <<setw(16) <<"72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 7 - Swirly Bitz" << setw(16) << "28.50" << setw(31) <<"17 - Breakfast Steak" <<setw (14) <<"52.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 8 - Burger" << setw(21) << "35.75" << setw(27) <<"18 - Corned Beef" <<setw(18) <<"65.00 |" << endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 9 - Rice" << setw(23) <<"15.50" << setw(26) <<"19 - Longganisa" <<setw(19) <<"55.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 10 - Coffee" << setw(20) <<"15.00" << setw(31) <<"20 - Chicken Sausage" <<setw(14) <<"50.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
		cout <<"As you done ordering , Just type -1 \n";


}


int printCheck(menuItemType menuList[20])
{
int choice = 0;
int cash ;
double total1, total2 ,total3, total4;

while(choice != -1)
{
cout <<"\n";
	cout <<" Enter your Choice:   ";
	
cin >> choice;

cout <<"\n";

switch(choice)
{
	case -1:
	cout <<"You're Done Ordering !! Thank You !!\n";
	break;

	case 1:
	cout <<setw(10) <<menuList[0].name << setw(30) << menuList[0].price;
	total = total + menuList[0].price;
	cout <<"\n";
	break;
	case 2:
	cout <<setw(14) <<menuList[1].name << setw(26) << menuList[1].price;
	cout <<"\n";
	total = total + menuList[1].price;
	break;
	case 3:
	cout <<setw(11) <<menuList[2].name << setw(29) << menuList[2].price ;
	total = total + menuList[2].price;
	cout <<"\n";
	break;
	case 4:
	cout <<setw(13) <<menuList[3].name << setw(26) << menuList[3].price;
	total = total + menuList[3].price;
	cout <<"\n";
	break;
	case 5:
	cout <<setw(11) <<menuList[4].name << setw(28) << menuList[4].price;
	total = total + menuList[4].price;
	cout <<"\n";
	break;
	case 6:
	cout <<setw(13) <<menuList[5].name << setw(27) << menuList[5].price;
	total = total + menuList[5].price;
	cout <<"\n";
	break;
	case 7:
	cout <<setw(12) <<menuList[6].name << setw(27) << menuList[6].price;
	total = total + menuList[6].price;
	cout <<"\n";
	break;
	case 8:
	cout <<setw(7) <<menuList[7].name << setw(33) << menuList[7].price;
	total = total + menuList[7].price;
	cout <<"\n";
	break;
	case 9:
	cout <<setw(5) <<menuList[8].name << setw(35) << menuList[8].price;
	total = total + menuList[8].price;
	cout <<"\n";
	break;
	case 10:
	cout << menuList[9].name << setw(30) << menuList[9].price;
	total = total + menuList[9].price;
	cout <<"\n";
	break;
	case 11:
	cout <<setw(13) <<menuList[10].name << setw(27) << menuList[10].price;
	total = total + menuList[10].price;
	cout <<"\n";
	break;
	case 12:
	cout <<setw(15) <<menuList[11].name << setw(22) << menuList[11].price;
	total = total + menuList[11].price;
	cout <<"\n";
	break;
	case 13:
	cout <<setw (10) <<menuList[12].name << setw(27) << menuList[12].price;
	total = total + menuList[12].price;
	cout <<"\n";
	break;
	case 14:
	cout <<setw(10) <<menuList[13].name << setw(29) << menuList[13].price;
	total = total + menuList[13].price;
	cout <<"\n";
	break;
	case 15:
	cout <<setw(10) <<menuList[14].name << setw(27) << menuList[14].price;
	total = total + menuList[14].price;
	cout <<"\n";
	break;
	case 16:
	cout <<setw(14) <<menuList[15].name << setw(23) << menuList[15].price;
	total = total + menuList[15].price;
	cout <<"\n";
	break;
	case 17:
	cout <<setw(16) <<menuList[16].name << setw(23) << menuList[16].price;
	total = total + menuList[16].price;
	cout <<"\n";
	break;
	case 18:
	cout <<setw(12) <<menuList[17].name << setw(25) << menuList[17].price;
	total = total + menuList[17].price;
	cout <<"\n";
	break;
	case 19:
	cout <<setw(11) <<menuList[18].name << setw(28) << menuList[18].price;
	total = total + menuList[18].price;
	cout <<"\n";
	break;
	case 20:
	cout <<setw(16) <<menuList[19].name << setw(23) << menuList[19].price;
	total = total + menuList[19].price;
	cout <<"\n";
	break;
	
	
	
	default:
		cout <<"Choices must be between 1 and 20 onLy. . .\n";
	break;
}


}

	cout <<"\nWelcome to Jollibee !" << endl;
	cout <<"\n";
	cout <<"Amount Due"  << setw(14) << setprecision(4) << total  << endl;
	
	total2 = total *.12;
	cout <<"Tax 12% VAT" << setw(13) << setprecision(2) <<total2 <<endl;
		
	total3 = total2 + total;	
	cout <<"Total Amount" << setw(12) << setprecision(4) << total3  << endl;
	cout <<"\n";
	cout <<"Cash : ";
	cin >>  cash ;
	total4 = cash -  total3;
	cout <<"Change :" <<total4  <<endl;
	
	std::cout <<"Date :" << currentDateTime() << std::endl;
	cout <<"Come back Again !!\n";
	system("PAUSE");
	
	getch ();
}

This post has been edited by CellulaS: 06 October 2012 - 09:34 AM

Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is offline

  • member icon


Reputation: 4140
  • View blog
  • Posts: 12,883
  • Joined: 25-December 09

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 09:33 AM

Quote

i have been trying to figure how to use both int,float function and void function

I suggest you start by studying the links provided in my signature. They should help you better understand functions.

Quote

I was wondering how can i add another menu from my other menu


What have you tried?

Jim
Was This Post Helpful? 1
  • +
  • -

#8 CellulaS  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 19-June 12

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 09:46 AM

Thanks Jim I read all about the function and i understand a little bit what i dont understand is how to to combine int, float function to a void function. i already setup the menu i already made my function for my output my problem is where should i put them ? because i tried everything there no output display...

Here my code for my output/input display where should i put it ? tried and tried keep getting into a problem
int printCheck(menuItemType menuList[20])
{
int choice = 0;
int cash ;
double total1, total2 ,total3, total4;

while(choice != -1)
{
cout <<"\n";
	cout <<" Enter your Choice:   ";
	
cin >> choice;

cout <<"\n";

switch(choice)
{
	case -1:
	cout <<"You're Done Ordering !! Thank You !!\n";
	break;

	case 1:
	cout <<setw(10) <<menuList[0].name << setw(30) << menuList[0].price;
	total = total + menuList[0].price;
	cout <<"\n";
	break;
	case 2:
	cout <<setw(14) <<menuList[1].name << setw(26) << menuList[1].price;
	cout <<"\n";
	total = total + menuList[1].price;
	break;
	case 3:
	cout <<setw(11) <<menuList[2].name << setw(29) << menuList[2].price ;
	total = total + menuList[2].price;
	cout <<"\n";
	break;
	case 4:
	cout <<setw(13) <<menuList[3].name << setw(26) << menuList[3].price;
	total = total + menuList[3].price;
	cout <<"\n";
	break;
	case 5:
	cout <<setw(11) <<menuList[4].name << setw(28) << menuList[4].price;
	total = total + menuList[4].price;
	cout <<"\n";
	break;
	case 6:
	cout <<setw(13) <<menuList[5].name << setw(27) << menuList[5].price;
	total = total + menuList[5].price;
	cout <<"\n";
	break;
	case 7:
	cout <<setw(12) <<menuList[6].name << setw(27) << menuList[6].price;
	total = total + menuList[6].price;
	cout <<"\n";
	break;
	case 8:
	cout <<setw(7) <<menuList[7].name << setw(33) << menuList[7].price;
	total = total + menuList[7].price;
	cout <<"\n";
	break;
	case 9:
	cout <<setw(5) <<menuList[8].name << setw(35) << menuList[8].price;
	total = total + menuList[8].price;
	cout <<"\n";
	break;
	case 10:
	cout << menuList[9].name << setw(30) << menuList[9].price;
	total = total + menuList[9].price;
	cout <<"\n";
	break;
	case 11:
	cout <<setw(13) <<menuList[10].name << setw(27) << menuList[10].price;
	total = total + menuList[10].price;
	cout <<"\n";
	break;
	case 12:
	cout <<setw(15) <<menuList[11].name << setw(22) << menuList[11].price;
	total = total + menuList[11].price;
	cout <<"\n";
	break;
	case 13:
	cout <<setw (10) <<menuList[12].name << setw(27) << menuList[12].price;
	total = total + menuList[12].price;
	cout <<"\n";
	break;
	case 14:
	cout <<setw(10) <<menuList[13].name << setw(29) << menuList[13].price;
	total = total + menuList[13].price;
	cout <<"\n";
	break;
	case 15:
	cout <<setw(10) <<menuList[14].name << setw(27) << menuList[14].price;
	total = total + menuList[14].price;
	cout <<"\n";
	break;
	case 16:
	cout <<setw(14) <<menuList[15].name << setw(23) << menuList[15].price;
	total = total + menuList[15].price;
	cout <<"\n";
	break;
	case 17:
	cout <<setw(16) <<menuList[16].name << setw(23) << menuList[16].price;
	total = total + menuList[16].price;
	cout <<"\n";
	break;
	case 18:
	cout <<setw(12) <<menuList[17].name << setw(25) << menuList[17].price;
	total = total + menuList[17].price;
	cout <<"\n";
	break;
	case 19:
	cout <<setw(11) <<menuList[18].name << setw(28) << menuList[18].price;
	total = total + menuList[18].price;
	cout <<"\n";
	break;
	case 20:
	cout <<setw(16) <<menuList[19].name << setw(23) << menuList[19].price;
	total = total + menuList[19].price;
	cout <<"\n";
	break;
	
	
	
	default:
		cout <<"Choices must be between 1 and 20 onLy. . .\n";
	break;
}


}

	cout <<"\nWelcome to Jollibee !" << endl;
	cout <<"\n";
	cout <<"Amount Due"  << setw(14) << setprecision(4) << total  << endl;
	
	total2 = total *.12;
	cout <<"Tax 2%" << setw(13) << setprecision(2) <<total2 <<endl;
		
	total3 = total2 + total;	
	cout <<"Total Amount" << setw(12) << setprecision(4) << total3  << endl;
	cout <<"\n";
	cout <<"Cash : ";
	cin >>  cash ;
	total4 = cash -  total3;
	cout <<"Change :" <<total4  <<endl;
	
	std::cout <<"Date :" << currentDateTime() << std::endl;
	cout <<"Come back Again !!\n";
	system("PAUSE");
	
	getch ();
}



example just wanna know how to combine int function and void function if its possible

int getData(menuItemType menuList[20])
{

	menuList[0].name = "Plain Egg";
	menuList[0].price = 15.45;
	menuList[1].name = "Bacon and Egg";
	menuList[1].price = 34.75;
	menuList[2].name = "ChickenJoy";
	menuList[2].price = 89.75;
	menuList[3].name = "French Fries";
	menuList[3].price = 25.50;


void direction(int ans)
{
}


Here my code for my fast food billing what i dont understand my output keep getting a problem or an error sorry if i ask too much im trying so hard to figure what when wrong. i remove my output code so you could teach me where should i put it
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <iomanip.h>
#include <time.h>

using namespace std;


const std::string currentDateTime() {

    time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    tstruct = *localtime(&now);
  
    strftime(buf, sizeof(buf), "%m / %d / %y - %I: %M: %S %p", &tstruct);

    return buf;
}



struct menuItemType

{
	
	string name;
	double price;

};


	double tax, total = 0;

	int getData(menuItemType menuList[20]);
	int showMenu(menuItemType menuList[20]);
	int ComboMenu(menuItemType menuList[20]);
	int SingleMenu(menuItemType menuList[20]);
	int printCheck(menuItemType menuList[20]);

	int main()
{
	menuItemType menuList[20];


    char ch;
       do {
        
        cout << "\n\t ";
        cout << "\n\t  >>Welcome<<         ";
        cout << "\n\t_____________________";
        cout << "\n\n\t[1] Menu List";
        cout << "\n\n\t[2] Combo Meals";
        cout << "\n\n\t[3] Single Meals";
        cout << "\n\n\t[4] PROCCED TO EXIT";
        cout << "\n\n\tPlease Select Option number[1-4] ";
        ch = getche();

        switch(ch) {
            case '1':
                showMenu(menuList);
               
                break;
            case '2':
                ComboMenu(menuList);
                break;
            case '3':
             SingleMenu(menuList);
                break;
            case '4':
               
            default :
                cout << "\a";
        }
    } while(ch != '4');

    return 0;
}
	;


int getData(menuItemType menuList[20])
{

	menuList[0].name = "Plain Egg";
	menuList[0].price = 15.45;
	menuList[1].name = "Bacon and Egg";
	menuList[1].price = 34.75;
	menuList[2].name = "ChickenJoy";
	menuList[2].price = 89.75;
	menuList[3].name = "French Fries";
	menuList[3].price = 25.50;
	menuList[4].name = "Coke Float";
	menuList[4].price = 35.50;
	menuList[5].name = "Coke (Large)";
	menuList[5].price = 25.15;
	menuList[6].name = "Swirly Bitz";
	menuList[6].price = 28.50;
	menuList[7].name = "Burger";
	menuList[7].price = 35.75;
	menuList[8].name = "Rice";
	menuList[8].price = 15.55;
	menuList[9].name = "Coffee";
	menuList[9].price = 15.00;
	menuList[10].name = "Jolly Hotdog";
	menuList[10].price = 45.75;
	menuList[11].name = "Palabok Fiesta";
	menuList[11].price = 61.00;
	menuList[12].name = "Spaghetti";
	menuList[12].price = 49.00;
	menuList[13].name = "mango Pie";
	menuList[13].price = 24.50;
	menuList[14].name = "Beef Tapa";
	menuList[14].price = 72.00;
	menuList[15].name = "Crispy Bangus";
	menuList[15].price = 72.00;
	menuList[16].name = "Breakfast Steak";
	menuList[16].price = 52.50;
	menuList[17].name = "COrned Beef";
	menuList[17].price = 65.00;
	menuList[18].name = "Longganisa";
	menuList[18].price = 55.50;
	menuList[19].name = "Chicken Sausage";
	menuList[19].price = 50.50;

}

int showMenu(menuItemType menuList[20])
{

	cout <<"Welcoome to Jollibee !! Enjoy your Food !!!\n";
	cout <<"Please Select Your Order\n";
	cout <<"\n";

	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"|   MENU LIST                                                                |\n";
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 1 - Plain Egg" << setw(18) << "15.45" <<" |" <<setw(26) <<"11 - Jolly Hotdog" <<setw (17) <<"45.75 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 2 - Bacon and Egg" << setw(14) << "34.75" << setw(30) <<"12 - Palabok Fiesta" <<setw(15) <<"61.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 3 - ChickenJoy" << setw(17) << "89.75" << setw(25) <<"13 - Spaghetti" <<setw(20) <<"49.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 4 - French Fries" << setw(15) << "25.50" << setw(25) <<"14 - Mango Pie" <<setw(20) <<"24.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 5 - Coke Float" << setw(17) << "35.50" << setw(25) <<"15 - Beef Tapa" <<setw(20) <<"72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 6 - Coke (Large)" << setw(15) << "25.15" << setw(29) <<"16 - Crispy Bangus" <<setw(16) <<"72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 7 - Swirly Bitz" << setw(16) << "28.50" << setw(31) <<"17 - Breakfast Steak" <<setw (14) <<"52.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 8 - Burger" << setw(21) << "35.75" << setw(27) <<"18 - Corned Beef" <<setw(18) <<"65.00 |" << endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 9 - Rice" << setw(23) <<"15.50" << setw(26) <<"19 - Longganisa" <<setw(19) <<"55.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 10 - Coffee" << setw(20) <<"15.00" << setw(31) <<"20 - Chicken Sausage" <<setw(14) <<"50.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
		


}

int ComboMenu(menuItemType menuList[20])
{

	cout <<"Welcoome to Jollibee !! Enjoy your Food !!!\n";
	cout <<"Please Select Your Order\n";
	cout <<"\n";

	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"|   MENU LIST                                                                |\n";
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 1 - Plain Egg" << setw(18) << "15.45" <<" |" <<setw(26) <<"11 - Jolly Hotdog" <<setw (17) <<"45.75 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 2 - Bacon and Egg" << setw(14) << "34.75" << setw(30) <<"12 - Palabok Fiesta" <<setw(15) <<"61.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 3 - ChickenJoy" << setw(17) << "89.75" << setw(25) <<"13 - Spaghetti" <<setw(20) <<"49.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 4 - French Fries" << setw(15) << "25.50" << setw(25) <<"14 - Mango Pie" <<setw(20) <<"24.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 5 - Coke Float" << setw(17) << "35.50" << setw(25) <<"15 - Beef Tapa" <<setw(20) <<"72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 6 - Coke (Large)" << setw(15) << "25.15" << setw(29) <<"16 - Crispy Bangus" <<setw(16) <<"72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 7 - Swirly Bitz" << setw(16) << "28.50" << setw(31) <<"17 - Breakfast Steak" <<setw (14) <<"52.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 8 - Burger" << setw(21) << "35.75" << setw(27) <<"18 - Corned Beef" <<setw(18) <<"65.00 |" << endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 9 - Rice" << setw(23) <<"15.50" << setw(26) <<"19 - Longganisa" <<setw(19) <<"55.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 10 - Coffee" << setw(20) <<"15.00" << setw(31) <<"20 - Chicken Sausage" <<setw(14) <<"50.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
		


}
int SingleMenu(menuItemType menuList[20])
{

	cout <<"Welcoome to Jollibee !! Enjoy your Food !!!\n";
	cout <<"Please Select Your Order\n";
	cout <<"\n";

	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"|   MENU LIST                                                                |\n";
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 1 - Plain Egg" << setw(18) << "15.45" <<" |" <<setw(26) <<"11 - Jolly Hotdog" <<setw (17) <<"45.75 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 2 - Bacon and Egg" << setw(14) << "34.75" << setw(30) <<"12 - Ice Cream " <<setw(15) <<"61.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 3 - ChickenJoy" << setw(17) << "89.75" << setw(25) <<"13 - Spaghetti" <<setw(20) <<"49.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 4 - French Fries" << setw(15) << "25.50" << setw(25) <<"14 - Mango Pie" <<setw(20) <<"24.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 5 - Coke Float" << setw(17) << "35.50" << setw(25) <<"15 - Beef Stew" <<setw(20) <<"72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 6 - Coke (Large)" << setw(15) << "25.15" << setw(29) <<"16 - Crispy Chicken" <<setw(16) <<"72.00 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 7 - Swirly Bitz" << setw(16) << "28.50" << setw(31) <<"17 - Breakfast Steak" <<setw (14) <<"52.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 8 - Burger" << setw(21) << "35.75" << setw(27) <<"18 - Corned Beef" <<setw(18) <<"65.00 |" << endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 9 - Rice" << setw(23) <<"15.50" << setw(26) <<"19 - Longganisa" <<setw(19) <<"55.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
	cout <<"| 10 - Coffee" << setw(20) <<"15.00" << setw(31) <<"20 - Chicken Sausage" <<setw(14) <<"50.50 |" <<endl;
	cout <<"|----------------------------------------------------------------------------|\n";
		


}

This post has been edited by CellulaS: 06 October 2012 - 09:51 AM

Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg  Icon User is offline

  • member icon


Reputation: 4140
  • View blog
  • Posts: 12,883
  • Joined: 25-December 09

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 09:52 AM

Please explain the following:

Quote

example just wanna know how to combine int function and void function if its possible


What do you actually mean by "combine". Do you mean call a function from another function? Or do you want to know how to have a function that returns nothing (void) that can modify a value in your calling function?


I suggest you write a small program that illustrates your question/problem. Just include enough information to illustrate your problem.


Jim
Was This Post Helpful? 0
  • +
  • -

#10 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1707
  • View blog
  • Posts: 3,275
  • Joined: 30-May 10

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 10:17 AM

> 129 int showMenu(menuItemType menuList[20])
and
> 164 int ComboMenu(menuItemType menuList[20])
These need to use the supplied array of menu items, and a for loop.

NOT 20+ lines of copy/pasted code.

> 133 int printCheck(menuItemType menuList[20])
You sort of got the idea here, but it can be improved with a bit more thought about how to use iomanip to generate a nice tabular menu.


The next idea would be to have something like
// array of integers, counting how many of each menuitem the customer ordered.
int customerOrder[20];


Initially, this is filled with zeros.

So if menuitem 3 happens to be "French Fries", and the customer orders 2 portions, then you set customerOrder[3] = 2;

Eg.
cout << "What item? ";
cin >> menuItem; // will be an integer, you printed out when displaying the menu
cout << "How many? ";
cin >> amount;
customerOrder[menuItem] = amount;


Now, when you come to printCheck(), you again loop over the customerOrder array, and only print those where the value is not zero (remember, you initialised them all to 0).
Was This Post Helpful? 0
  • +
  • -

#11 CellulaS  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 19-June 12

Re: Got A Question How Do I Optimize My Code?

Posted 06 October 2012 - 08:25 PM

Sorry About that copy and pasted code Salem_C it was 4:00 Am when i was coding it i was already sleepy my eye where barely open Thanks about the idea i finally got my code working i do still have some question about the customerOrder[20] how should i implement this.

Hey Jim was wondering if i could use the int function for my computation
and using the void function as for my display is this possible ?
int getData(menuItemType menuList[20])
{

	menuList[0].name = "Plain Egg";
	menuList[0].price = 15.45;
	menuList[1].name = "Bacon and Egg";
	menuList[1].price = 34.75;
	menuList[2].name = "ChickenJoy";
	menuList[2].price = 89.75;
	menuList[3].name = "French Fries";
	menuList[3].price = 25.50;
	menuList[4].name = "Coke Float";
	menuList[4].price = 35.50;
	menuList[5].name = "Coke (Large)";
	menuList[5].price = 25.15;
	menuList[6].name = "Swirly Bitz";
}

instead of using int showMenu i would like to use void and having both int function and void function in my code
void display() { 
  showMenu(menuList);
}

This post has been edited by CellulaS: 06 October 2012 - 08:27 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1