1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
switch(order1)(order2)(order3(order4)(order5) { case 1: cout<<"Large Pepperoni Pizza =P200\n"; break; case 2: cout<<"Medium Pepperoni Pizza =P150\n"; break; case 3: cout<<"Small Pepperoni Pizza =P100\n"; break; case 4: cout<<"Large Mushroom Pizaa =P200\n"; break; case 5: cout<<"Medium Mushroom Pizza =P150\n"; break; case 6: cout<<"Coke =P15\n"; break; case 7: cout<<"Royal =P15\n"; break; case 8: cout<<"Sprite =P15\n"; break; case 9: cout<<"Pine Apple Juice =P20\n"; break; case 10: cout<<"Apple Juice =P20\n"; break; case 11: cout<<"Beef Barbeque =P30\n"; break; case 12: cout<<"Pork Barbeque =P20\n"; break; case 13: cout<<"Chicken Barbeque =P25\n"; break; case 14: cout<<"Spaghetti =P60\n"; break; case 15: cout<<"Carbonara =P80\n"; break; case 16: cout<<"Fruit Salad =P75\n"; break; case 17: cout<<"Macaroni Salad =P50\n"; break; default: cout<<"Wrong Order Code !\n"; }
123456789101112131415161718192021222324252627282930313233343536
switch ( order1 ) { case 1: // ... break; case 2: // ... break; default: switch ( order2 ) { case 1: // ... break; case 2: // ... break; default: switch ( order3 ) { case 1: // ... break; default: // ... break; } break; } break; }
123456789101112131415161718192021222324252627
int main () { int orders[5] = {1,2,3,4,5}; for( int index = 0 ; index < 5; index++) { switch(orders[index]) { case 1: std::cout<<"Large Pepperoni Pizza =P200\n"; break; case 2: std::cout<<"Medium Pepperoni Pizza =P150\n"; break; case 3: std::cout<<"Small Pepperoni Pizza =P100\n"; break; case 4: std::cout<<"Large Mushroom Pizaa =P200\n"; break; //... default: std::cout<<"Wrong Order Code !\n"; } } return 0; }
123456789101112
. . . switch(order1 || order2 || order3 || order4 || order5) { . . // cases go here . } . . .
12345678910111213
std::vector<std::string> options(numberOfOptions); options[0] = "Large Pepperoni Pizza =P200"; options[1] = "Medium Pepperoni Pizza =P150"; options[2] = "Small Pepperoni Pizza =P100"; // ... std::vector<int> orders(numberOfOrders, -1); // Set orders to "nothing". // Read orders into vector. // ... // Print out orders. for (auto it = 0; it < orders.size(); ++it) { if (orders[it] == -1) continue; std::cout << options[orders[i]] << std::endl; }