Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
the c++ program should do the following:
1) foods should have 2 types of each
2) Example: pizza: cheese pizza, chicken pizza
burger: beef burger, chicken burger
3) lets the user if he wants to order more
4) calculates the price of all he ordered and displays the total

What I have tried:

#include<iostream>

using namespace std;

int main()
{
	int price, price2;
    int menu;
    int order;
    int change;
    int quantity, quantity2;
    int flavor;
    int another;



    asd:

    cout << "Welcome to ... snack" << endl;
    cout << "" << endl;
    cout << "Options" << endl;
    cout << "1 - Ice cream" << endl;
    cout << "2 - Juice" << endl;
    cin >> menu;

    switch (menu) {
    case 1:
        price = 8;
        cout << "You ordered an Ice cream" << endl;
        cout << "What flavor would you like?" << endl;
        cout << "1 - Chocolate" << endl;
        cout << "2 - Vanilla" << endl;
        cin >> flavor;
        if (flavor == 1) {
            cout << "You ordered Chocolate Icecream" << endl;
        } else if (flavor == 2) {
            cout << "You ordered Vanilla Icecream" << endl;
        } else {
            cout << "option does not exist" << endl;
        goto asd;
        }
        cout << "It costs  " << price << endl;
        cout << "How many would you like?" << endl;
        cin >> quantity;
        cout << "Do you want to order another?" << endl;
        cout << "0 - no" << endl;
        cout << "1 - yes" << endl;
        cin >> another;
        if (another == 0) {
                cout << "enter amount to pay" << endl;
                cin >> order;
                change = order - quantity * price;
                cout << "change is  " << change << endl;

        } else if (another == 1){
            goto asd;
        }

        break;
    case 2:
        price2 = 15;
        cout << "You ordered a juice" << endl;
        cout << "What flavor would you like?" << endl;
        cout << "1 - Orange" << endl;
        cout << "2 - Apple" << endl;
        cin >> flavor;
        if (flavor == 1) {
            cout << "You ordered Orange Juice" << endl;
        } else if (flavor == 2) {
            cout << "You ordered Apple Juice" << endl;
        } else {
            cout << "option does not exist"  << endl;
        goto asd;
        }
        cout << "It costs P " << price2 << endl;
        cout << "How many  would you like? " << endl;
        cin >> quantity2;
        cout << "enter amount to pay" << endl;
        cin >> order;

                cout << "Do you want to order another?" << endl;
        cout << "0 - no" << endl;
        cout << "1 - yes" << endl;
        cin >> another;
        if (another == 0) {
                cout << "enter amount to pay" << endl;
                cin >> order;
                change = order - quantity * price;
                cout << "change is  " << change << endl;
            break;
        } else if (another == 1){
            goto asd;
        }

        change = order - price2 * quantity2;

        cout << "change is  " << change << endl;

        break;


        break;
    default:
        cout << "option does not exist" << endl;
        goto asd;
        break;

    }
      return 0;
  }
Posted
Updated 18-Oct-22 18:32pm
Comments
CPallini 19-Oct-22 2:36am    
You know C++ supports Object Oriented Programming, don't you?

1 solution

First off, get rid of the label and goto statements: use a loop such as a while or do ... while instead. And then forget that goto even exists for a few years until you understand when it is appropriate to use one!

Second, read the question carefully: where does it tell you to ask the user how much he is willing to pay for the food? Is that normal in shops where you live, or does the shop set the price the user is expected to pay for goods?

Then fix your indentation - it's all over the place, and that makes code hard to read.

And change the names of your variables to reflect what they are used for: menu for example would make you code more readable as choice or userSelection. menu implies it contains a list of items the user can select from, rather than the users response to that list.

I'd also suggest that you consider using functions to break up your code and make it easier to read!
 
Share this answer
 
Comments
CPallini 19-Oct-22 2:36am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900