0

I don't know how to ask about this since im new at c++ and im not good at English sorry for that.

So Id made a restaurant menu in c++ where there's a list of items in the menu , but the problem is I can only choose 1 item and sum it up, How can I make choose multiple items in the menu like for example

Menu list

  1. food 1
  2. food 2
  3. food 3

Choose an item above : 1 3 then show what are the list of what user inputs and sum it up and its prices.

I was thinking about using while loop, that while user input char 'c' means checkout it will sum it up everything

0

2 Answers 2

2

What you need to do is to use a flag variable to determine if the user is done adding stuff to the cart.

For example, the interface looks like this

Menu list
-
food 1
food 2
food 3
-
quit (q)

Then its just a matter of seeing if the input == "q" and breaking out of the loop if it is

while(true){ 
    cin << input;
    if(input == "q") break;
    else //other-logic-here
}
Sign up to request clarification or add additional context in comments.

Comments

0

Way to implement your idea:

const int menu[]{ 10,20,30 };
int a=0, b=0, c=0;

cout << "enter your mix.(a=10,b=20 and c=30). Press other keys to sum." << endl;
char input;
cin >> input;

while (input != 'q')
{
    switch (input)
    {
        case 'a'  :a += menu[0]; break;
        case 'b'  :b += menu[1]; break;
        case 'c'  :c += menu[2]; break;
        default:
            cout << a << " + " << b << " + " << c <<" = "<<  a + b + c << endl;
            a = b = c = 0;
            cout << "enter a,b,or c." << endl;
    }
    cin >> input;
}

Results:

 enter your mix.(a=10,b=20 and c=30). Press other keys to sum.
b
b
c
c
c
7
0 + 40 + 90 = 130
enter a,b,or c.

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.