1

I have a for loop where when the quantity number is entered, the loop will run for the amount of quantity entered. But unfortunately the output summary only displays one output.

For example, when user enters the quantity number of 2, the loop of choosing the pizza, size and add on runs twice but the summary output in this particular line cout << sizetype << "/t" << pizzatype << "/t" << price << endl; only displays one output. Nevertheless, I want to display both of the output which has been entered by user.

Need help on this.

case 2:
    		
          cin >> quantity;
          for(int i=0; i<quantity; i++)
    			cout << "**Pizza Favourites**" << endl;
    			cout << "1. Italian Aloha" << endl;
    			cout << "2. Vegi Lover" << endl;
    			cout << "3. Ocean Delite" << endl << endl;
    			cout << "Choose Your Pizza (Enter Integer 1-3 Only) : ";
    			cin >> pizza;
    			switch (pizza)
    			{
    			case 1:
    				cout << "You've ordered Italian Aloha Pizza" << endl;
    				pizzatype = "Italian Aloha Pizza";
    				break;
    			case 2:
    				cout << "You've ordered Vegi Lover Pizza" << endl;
    				pizzatype = "Vegi Lover Pizza";
    				break;
    			case 3:
    				cout << "You've ordered Ocean Delite Pizza" << endl;
    				pizzatype = "Ocean Delite Pizza";
    				break;
    			default:
    				cout << "Invalid Input" << endl;
    				break;
    			}

    			cout << "**Pizza Sizes**" << endl;
    			cout << "1. Regular (R)" << endl;
    			cout << "2. Large (L)" << endl;
    			cout << "3. X-Large (X)" << endl << endl;
    			cout << "Choose Your Pizza Size (Enter Integer 1-3 Only) : ";
    			cin >> size;
    			switch (size)
    			{
    			case 1:
    				cout << "You've Chose Regular Sized Pizza" << endl;
    				sizetype = "Regular";
    				price = newRegular;
    				break;
    			case 2:
    				cout << "You've Chose Large Sized Pizza" << endl;
    				sizetype = "Large";
    				price = newLarge;
    				break;
    			case 3:
    				cout << "You've Chose X-Large Sized Pizza" << endl;
    				sizetype = "X-Large";
    				price = newXlarge;
    				break;
    			default:
    				cout << "Invalid Input" << endl;
    				break;
    			}
}
    			cout << "**Add On**" << endl;
    			cout << "Do You Want To Add On Extra Cheese ? (Enter Y for Yes and N for No) : ";
    			cin >> yesNo;
    			switch (yesNo)
    			{
    			case 'Y':
    				cout << "More Cheese, More Fun !" << endl;
    				cheesePrice = newCheese;
    				break;
    			case 'N':
    				cout << "No Extra Cheese Required !" << endl;
    				cheesePrice;
    				break;
    			default:
    				cout << "Invalid Input" << endl;
    				break;
    			}

    			cout << "WONDER PIZZA" << endl;
    			cout << "************" << endl;
    			cout << sizetype << "/t" << pizzatype << "/t" << price << endl;
    			cout << "Extra Cheese : " << cheesePrice << endl;
    			total = price + cheesePrice;
    			cout << "Total Payment : " << total << endl;
    			cout << "Please Insert Your Payment : " << payment << endl;
    			change = payment - total;
    			cout << "Change" << change << endl;
    			break;

3
  • Create sub functions would help readability. Commented Nov 21, 2017 at 13:58
  • 1
    Never hardcode a password. There is no exception. Commented Nov 21, 2017 at 14:01
  • Don't just post your excercise sheet! Tell us what you don't understand and we might be able to help you but this is not a site for homework assistence. Commented Nov 21, 2017 at 14:01

1 Answer 1

3

Yes, you can nest a switch statement inside the case of an outer switch statement.

The break on an inner case will be in the context of the inner switch.

(Does that answer your question? I wasn't sure that was your question.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.