building a program for cafe menu. help!

let say I want one regular coffee and one croissant. it only shows "you have ordered: 1croissant (0.75)" I want it to show: "you have ordered: 1 regular coffee ($1.5), 1Croissant ($0.75)" how do i do that?

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
      #include <string>
    #include <iostream>
    
    
    using namespace std;
    
    int main()
    
    {
    
     int choice; //declare variables
    double q=0;
    double total=0;
    string input ="Y"; //default input is yes
    string input2,input3,input4;
    double array [13]={1.5, 1.25,2.25,2.5,2.25,2.75,2.5,1,1.25, 1.25, 0.75, 1, 0.75}; // declare array
    string array1 [13]={"regular coffee ($1.50)", "decaf coffee ($1.25)", "Americano (2.25)", "Latte ($2.50)", "Espresso (2.25)", "Cappuccino ($2.75)", "Macchiato ($2.50)","Plain Muffin ($1.00)", "Raspberry Muffin ($1.25)", "Scone ($0.75)", "Blueberry Scone ($1.00)", "Croissant ($0.75)"};
    
    while (input=="Y" || input=="y"){ // while loop when input=y
        cout << "******Hunter Cafe CMS*******" << endl; //menu display
    cout <<"Welcome! Here is the Cafe Menu:"<< endl;
    cout <<"**Coffee**        **Cost($)**      **Snacks**        **Cost($)**"<<endl;
    cout <<"1) Regular        1.50             8)Plain Muffin      1.00"<<endl;
    cout <<"2) Decaf          1.25             9)Blueberry Muffin  1.25" <<endl;
    cout <<"3) Americano      2.25             10)Raspberry Muffin 1.25" <<endl;
    cout <<"4) Latte          2.50             11)Scone            0.75" <<endl;
    cout << "5) Espresso       2.25             12)Blueberry Scone  1.00" <<endl;
    cout << "6) Cappuccino     2.75             13)Croissant        0.75" <<endl;
    cout << "7) Macchiato      2.50"<<endl;
    cout <<"what would you like?(1-13):" <<endl;
    cin >> choice;
    cout << "how many would you like?:" <<endl;
    cin >> q; //quantity
    cout <<"Would you like anything else?(Y/N):"<<endl;
    cin >> input;
        total= (q*array[choice-1])+total;
        if(input=="N" ||input=="n"){
            cout<<"Are you satisfied with your order?(Y/N)"<<endl;
            cin >>input2;
            if (input2=="Y"){
                cout << "Thank you for shopping at Hunter Cafe CMS! Have a nice day!"<<endl;
            }
            
        }
    }
    
     switch(choice){
         case 0:
         cout <<"invalid response"<<endl;
         case 1:
            cout << "you have ordered: "<<q<<array1 [0] <<endl;
            cout << "your total is  $ "<<total<<endl;
            break;
         case 2:
            cout << "you have ordered: "<<q<<"Decaf coffee ($1.25)"<<endl;
            cout << "your total is  $ "<<total<<endl;
            break;
         case 3:
            cout << "you have ordered: "<<q<< "Americano ($2.25)"<< endl;
            cout << "your total is  $ "<<total<<endl;
            break;
         case 4:
            cout<< "you have ordered: "<<q<< "Latte ($2.50)" <<endl;
            cout << "your total is  $ "<<total<<endl;
            break;
         case 5:
            cout<< "you have ordered: "<<q<< "Espresso ($2.25)"<<endl;
            cout << "your total is $  "<<total<<endl;
            break;
        case 6:
            cout<< "you have ordered: "<<q<< "Cappuccino ($2.75)"<<endl;
            cout << "your total is  $ "<<total<<endl;
            break;
        case 7:
            cout<< "you have ordered: "<<q<< "Macchiato ($2.50)"<<endl;
            cout << "your total is $  "<<total<<endl;
            break;
        case 8:
            cout<< "you have ordered: "<<q<< "plain Muffin ($1.00)"<<endl;
            cout << "your total is $  "<<total<<endl;
            break;
        case 9:
            cout<< "you have ordered: "<<q<< "Blueberry Muffin ($1.25)"<<endl;
            cout << "your total is $  "<<total<<endl;
            break;
        case 10:
            cout<< "you have ordered: "<<q<< "Raspberry Muffin ($1.25)"<<endl;
            cout << "your total is $  "<<total<<endl;
            break;
        case 11:
            cout<< "you have ordered: "<<q<< "Scone ($0.75)"<<endl;
            cout << "your total is $  "<<total<<endl;
            break;
        case 12:
            cout<< "you have ordered: "<<q<< "Blueberry Scone ($1.00)"<<endl;
            cout << "your total is $ "<<total<<endl;
            break;
        case 13:
            cout<< "you have ordered: "<<q<< "Croissant ($0.75)"<<endl;
            cout << "your total is $ "<<total<<endl;
            break;
     }
     
        
     
    
    
     return 0;
    
    }
You would either need to put your switch statement inside the loop used to take the user's order, or you would need to create an array to keep track of what they ordered and how much of it and checking to see if they ordered something before outputting it to the screen.

Your program currently is fundamentally broken because your switch statement after the loop only checks the last choice the user made.
How can I differentiate each choice?
for example, if I buy coffee and scone, how can I cout "you have bought coffee and scone"?
Your program currently has two arrays: one with the price of items, one with the name of items. You'd only need to create one more to keep track of how much of each item a user ordered. Then you would use a for statement to iterate through all items, and if they quantity purchased is greater than zero, you would output to screen.
Can you give me an example or elaborate? I am new to C++, I dont know how that would work. Also, the sample is supposed to run like this :
Sample run:


******Hunter Cafe CMS*******
Welcome! Here is the Cafe Menu:

**Coffee** **Cost($)** **Snacks** **Cost($)**
1) Regular 1.50 8)Plain Muffin 1.00
2) Decaf 1.25 9)Blueberry Muffin 1.25
3) Americano 2.25 10)Raspberry Muffin 1.25
4) Latte 2.50 11)Scone 0.75
5) Espresso 2.25 12)Blueberry Scone 1.00
6) Cappuccino 2.75 13)Croissant 0.75
7) Macchiato 2.50


What would you like?(1-13): 1

How many would you like?: 2

Would you like anything else?(Y/N): Y

Here is the Cafe Menu:

**Coffee** **Cost($)** **Snacks** **Cost($)**
1) Regular 1.50 8)Plain Muffin 1.00
2) Decaf 1.25 9)Blueberry Muffin 1.25
3) Americano 2.25 10)Raspberry Muffin 1.25
4) Latte 2.50 11)Scone 0.75
5) Espresso 2.25 12)Blueberry Scone 1.00
6) Cappuccino 2.75 13)Croissant 0.75
7) Macchiato 2.50

What would you like?(1-13): 9

How many would you like?: 1

Would you like anything else?(Y/N): N

You have ordered: 2 Regular Coffee ($1.50), 1 Blueberry Muffin ($1.25)
Your total is: $4.25

Are you satisfied with your order?(Y/N): N

Would you like to add items to your order (1) or start over (2): 1

Here is the Cafe Menu:

**Coffee** **Cost($)** **Snacks** **Cost($)**
1) Regular 1.50 8)Plain Muffin 1.00
2) Decaf 1.25 9)Blueberry Muffin 1.25
3) Americano 2.25 10)Raspberry Muffin 1.25
4) Latte 2.50 11)Scone 0.75
5) Espresso 2.25 12)Blueberry Scone 1.00
6) Cappuccino 2.75 13)Croissant 0.75
7) Macchiato 2.50

What would you like?(1-13): 11

How many would you like?: 1

Would you like anything else?(Y/N): N

You have ordered: 2 Regular Coffee ($1.50), 1 Blueberry Muffin ($1.25), 1 Scone ($0.75)
Your total is: $5.00

Are you satisfied with your order?(Y/N): Y

Thank you for shopping at Hunter Cafe CMS! Have a nice day!
I'm pretty much saying you need a counter variable. If the counter for an item is greater than zero, then that should be a condition to output that item to the screen.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main (void)
{
    int choice;
    int bag_of_numbers[10] = {0};
    while (true)
    {
        cout << "Pick a number to add to the bag: ";
        cin >> choice;

        if (choice < 1 || choice > 10 )
            break;

        ++bag_of_numbers[choice - 1];
    }

    cout << "The numbers you chose: " << endl;
    for (int i = 0; i < 10; i++)
    {
        //check to see if numbers are in the bag. Only then will I output.
        if ( bag_of_numbers[i] > 0 )
            cout << "The number " << i + 1 << " is in the bag " << bag_of_numbers[i] << " times." << endl;
    }
}
Last edited on
Topic archived. No new replies allowed.