HELP WITH SWITCH STATEMENT c++

Can anyone help me with this?

I would first like to say I don't just want the answer so please at least provide me with what I should look up in order to solve this. I am a beginner and I have been working on this for 5+ hours and would just like to get it done before the day is over

"Write a program to help a customer order food from your fast-food joint. The program allows a customer to add (or remove) items from their order, until they finally place their order. The customer wants to know the cost and calories of the food being ordered. The customer can also clear their order and start over. Finally the customer places the order – or just quits without ordering anything."

How do I do the switch statements? if my code right now correct?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <cstdlib>
# include <string>
using namespace std;
int main()
{
    enum Type {Burger=1, Fries, Drink, Salad, Clear, Order, Quit};

    
        cout << "Place your order from JT's Burger Joint. This app shows your calories and cost as you add items to your food order. You can clear, order, or quit at any time.\n";
       cout << "Current order:  burger:0 fries:0 drink:0 salad:0 ice cream:0  TOTAL calories: 0  cost: $0.00\n";
        cout << "Choose: b)urger f)ries d)rink s)alad c)lear, o)order, q)uit: ";
   


switch (option) {
case Burger:
case Fries:     
case Drink:
case Salad:


/*
This should be the output: Place your order from John R's Burger Joint. This app shows your calories and cost
as you add items to your food order. You can clear, order, or quit at any time.

Current order:  burger:0 fries:0 drink:0 salad:0 ice cream:0  TOTAL calories: 0  cost: $0.00
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: b

Current order:  burger:1 fries:0 drink:0 salad:0 ice cream:0  TOTAL calories: 200  cost: $1.00
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: b

Current order:  burger:2 fries:0 drink:0 salad:0 ice cream:0  TOTAL calories: 400  cost: $2.00
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: c

Current order:  burger:0 fries:0 drink:0 salad:0 ice cream:0  TOTAL calories: 0  cost: $0.00
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: b

Current order:  burger:1 fries:0 drink:0 salad:0 ice cream:0  TOTAL calories: 200  cost: $1.00
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: f

Current order:  burger:1 fries:1 drink:0 salad:0 ice cream:0  TOTAL calories: 300  cost: $1.75
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: d

Current order:  burger:1 fries:1 drink:1 salad:0 ice cream:0  TOTAL calories: 450  cost: $3.00
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: s

Current order:  burger:1 fries:1 drink:1 salad:1 ice cream:0  TOTAL calories: 530  cost: $4.50
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: s

Current order:  burger:1 fries:1 drink:1 salad:2 ice cream:0  TOTAL calories: 610  cost: $6.00
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: w
  Invalid option, please try again.

Current order:  burger:1 fries:1 drink:1 salad:2 ice cream:0  TOTAL calories: 610  cost: $6.00
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: i

Current order:  burger:1 fries:1 drink:1 salad:2 ice cream:1  TOTAL calories: 910  cost: $7.75
Choose: b)urger f)ries d)rink s)alad i)ce cream c)lear, o)order, q)uit: o

Thank you for your order! Your total comes to: $7.75

Good-bye. Thank you for giving us the opportunity to serve you.

When user enters ‘q’ to quit at any time, exit the loop and provide a message; 
Sorry you decided not to order. Please try us again!
*/
Last edited on
Please don't post the same problem multiple times.
http://www.cplusplus.com/forum/general/280090/
sorry
You have an enum which means you can use Burger and Fries as numbers. However, you ask the user for input as letters.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <cstdlib>
# include <string>
using namespace std;
int main()
{
    enum Type { Burger = 1, Fries, Drink, Salad, Clear, Order, Quit };


    cout << "Place your order from JT's Burger Joint. This app shows your calories and cost as you add items to your food order. You can clear, order, or quit at any time.\n";
    cout << "Current order:  burger:0 fries:0 drink:0 salad:0 ice cream:0  TOTAL calories: 0  cost: $0.00\n";
    cout << "Choose: b)urger f)ries d)rink s)alad c)lear, o)order, q)uit: ";

    int option;
    cin >> option;


    switch (option) 
    {
    case Burger:
        cout << "Burger!\n";
        break;
    case Fries:
        cout << "Fries!\n";
        break;
    case Drink:
        cout << "Drink!\n";
        break;
    case Salad:
        cout << "Salad!\n";
        break;
    }

}


This would be the code using the enum you have.
Last edited on
Topic archived. No new replies allowed.