Beginners ORDERING SYSTEM QUERY!

Hi I Revised my code, here's the new one. I have some problems about this one, example. I just entered an invalid input on the question "What's your order?" but it'll skip the default: cout.but then just show all lines the cout on the first letter for example a you just ordered sweet and sour, how many order,order again, then the last part is the else cout. how can I go straight to default cout when i input an invalid answer in "whats your order", then how to loop on order again (y/n), if you put invalid choice, please do revised my program. any help is appreciate, im just a newbie please just adjust on this topics, if else, loop, switch case only, no void or str or namespace we havent done it yet.


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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include<conio.h>
#include<iostream.h>

int total,price,quota,bill=0,tbill;
char order,loop;

main()
{
do
{
clrscr();
cout<<"====================="<<endl;
cout<<"        MENU"<<endl;
cout<<"====================="<<endl;
cout<<"Dishes:"<<endl;
cout<<"(A)   Sweet and Sour Pork Php 600.00	   (D)   Pigar-Pigar    Php 900.00"<<endl;
cout<<"(B)   Bicol Express        Php 700.00	   (E)   Kare-Kare	Php 1000.00"<<endl;
cout<<"(C)   Beef Steak		 Php 800.00"<<endl;
cout<<"Rices:"<<endl;
cout<<"(F)   Plain		 Php 10.00	   (I)   Japanese	Php 18.00"<<endl;
cout<<"(G)   Fried		 Php 12.00	   (J)   Yang Chow      Php 25.00"<<endl;
cout<<"(H)   Brown		 Php 15.00"<<endl;
cout<<"Desserts:"<<endl;
cout<<"(K)   Ice Cream		 Php 30.00	   (N)	 Dried Mango    Php 45.00"<<endl;
cout<<"(L)   Halo-Halo		 Php 35.00         (O)   Leche Flan     Php 50.00"<<endl;
cout<<"(M)   Chocolate		 Php 40.00"<<endl;
cout<<"Drinks:"<<endl;
cout<<"(P)   Mineral Water	 Php 10.00         (S)   Gatorade       Php 26.00"<<endl;
cout<<"(Q)   Pepsi in Can	 Php 25.00         (T)   Monster Enery  Php 90.00"<<endl;
cout<<"(R)   Cocacola in Can	 Php 28.00"<<endl;
cout<<"Liquors:"<<endl;
cout<<"(U)   Emperador Lights    Php 110.00        (X)   Emperador Deluxe Php 300.00"<<endl;
cout<<"(V)   Red Horse Jumbo     Php 80.00         (Y)   OR.GY Lambanog  Php  100.00"<<endl;
cout<<"(W)   Black Label         Php 1555.00       (Z)   Jack Daniels     Php 2015.00"<<endl;

cout<<"What is Your Order?"<<endl;
cin>>order;

switch(order)
{
case 'a': case 'A':
cout<<"You Ordered Sweet and Sour Pork";
price=600;
break;
case 'b': case 'B':
cout<<"You Ordered Bicol Express";
price=700;
break;
case 'c': case 'C':
cout<<"You Ordered Beef Steak";
price=800;
break;
case 'd': case 'D':
cout<<"You Ordered Pigar-Pigar";
price=900;
break;
case 'e': case 'E':
cout<<"You Ordered Kare-Kare";
price=1000;
break;
case 'f': case 'F':
cout<<"You Ordered Plain Rice";
price=10;
break;
case 'g': case 'G':
cout<<"You Ordered Fried Rice";
price=12;
break;
case 'h': case 'H':
cout<<"You Ordered Brown Rice";
price=15;
break;
case 'i': case 'I':
cout<<"You Ordered Japanese Rice";
price=18;
break;
case 'j': case 'J':
cout<<"You Ordered Yang Chow Rice";
price=25;
break;
case 'k': case 'K':
cout<<"You Ordered Ice Cream";
price=30;
break;
case 'l': case 'L':
cout<<"You Ordered Halo-Halo";
price=35;
break;
case 'm': case 'M':
cout<<"You Ordered Chocolate";
price=40;
break;
case 'n': case 'N':
cout<<"You Ordered Dried Mango";
price=45;
break;
case 'o': case 'O':
cout<<"You Ordered Leche Flan";
price=50;
break;
case 'p': case 'P':
cout<<"You Ordered Mineral Water";
price=10;
break;
case 'q': case 'Q':
cout<<"You Ordered Pepsi in Can";
price=25;
break;
case 'r': case 'R':
cout<<"You Ordered Cocacola in Can";
price=28;
break;
case 's': case 'S':
cout<<"You Ordered Red Horse Beer (1 liter)";
price=80;
break;
case 't': case 'T':
cout<<"You Ordered Red Horse Beer (500 ml)";
price=40;
break;
case 'u': case 'U':
cout<<"You Ordered Emperador Lights";
price=110;
break;
case 'v': case 'V':
cout<<"You Ordered Emperador Deluxe";
price=300;
break;
case 'W': case 'w':
cout<<"You Ordered Red Horse Jumbo";
price=80;
break;
case 'x': case 'X':
cout<<"You Ordered OR.GY Lambanog";
price=100;
break;
case 'y': case 'Y':
cout<<"You Ordered Black Label";
price=1555;
break;
case 'z': case 'Z':
cout<<"You Ordered JACK DANIELS";
price=2015;
break;
default:
cout<<"Invalid Entry, Please Restart.";
break;
}

cout<<"           How Many Order/s?"<<endl;
cin>>quota;
bill+=price*quota;
cout<<"Your Total bill is Php  "<<bill<<endl;
cout<<"Order Again? Y/N"<<endl;
cin>>loop;

}while(loop=='Y'||loop=='y');
if (loop=='N' ||loop=='n')
{

total=bill*0.06;
tbill=total+bill;
cout<<"Your Bill is Php  "<<bill;
cout<<" + Service Charge (6%) of your bill is Php  "<<total<<endl;
cout<<"Your Total Bill is Php  "<<tbill<<endl;
cout<<" THANK YOU VERY MUCH! "<<endl;
}
else
{
cout<<"Invalid Choice, Please Restart";

}


getch();
return 0;
}
Last edited on
up
Please use code tags when posting code. Highlight the code and then click the <> button to the right of the edit window. Here is your code tagged and indented. More comments below.
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
#include<conio.h>
#include <iostream>


using std::cout;
using std::cin;
using std::endl;

main()
{
    clrscr();
    int a = 600, b = 700, y, c, d, e, f, g, h, i, j, k, l, total;
    char order, loop;


    cout << "=====================" << endl;
    cout << " MENU" << endl;
    cout << "=====================" << endl;
    cout << endl;
    cout << "Dishes:" << endl;
    cout << "(A) Sweet and Sour Pork Php 600.00" << endl;
    cout << "(B) Bicol Express Php 700.00" << endl;

    do {
        cout << "What do you want to order?" << endl;
        cin >> order;

        switch (order) {
        case 'a':
        case 'A':
            cout << "You ordered Sweet and Sour Pork";
            break;
        case 'b':
        case 'B':
            cout << "You Ordered Bicol Express";
            break;
        default:
            cout << "Invalid Entry";
            break;
        }
        cout << " How many order?" << endl;
        cin >> b;
        c = order * b;
        cout << "Your total bill Total Bill is " << c << endl;
        cout << "Order Again? Y/N";
        cin >> loop;

    } while (loop == 'Y' || loop == 'y');

    total = c * 0.6;
    cout << "Thank You, Your Total Bill + Service Charge is " << total << endl;
    getch();
    return 0;
}


To make this compile, add this before main():
1
2
3
using std::cout;
using std::cin;
using std::endl;


If line 38 detects an invalid entry, the code just keeps going. I suggest that you move the code that prints the menu and prompts for the order to a separate function. Here is some pseudo-code:
// Prompt for an order repeatedly until user enters a valid order. Return the order letter ('A' or 'B'):
1
2
3
4
5
6
7
8
9
10
11
12
13
char getOrder()
{
    while (true) {
        print the menu
        print the prompt
        get the order
        if order is valid {
            convert order to upper case
            return it
        }
        print "invalid entry"
     }
}

At line 43 you calculate the total, but you're using the letter that the user entered, not the cost.

Line 50 computes total as 60% of the last order. That doesn't seem right, but without knowing what you're supposed to compute I can't say for sure. If you're supposed to be adding up everything that the user orders, then you need to add to total inside the loop so you get each order. Also you must initialize total to 0 at line 12.
Hi I just edited the topic. please do help me again sir.
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include<conio.h>
#include<iostream.h>

int total,price,quota,bill=0,tbill;
char order,loop;

main()
{
do
{
clrscr();
cout<<"====================="<<endl;
cout<<"        MENU"<<endl;
cout<<"====================="<<endl;
cout<<"Dishes:"<<endl;
cout<<"(A)   Sweet and Sour Pork Php 600.00	   (D)   Pigar-Pigar    Php 900.00"<<endl;
cout<<"(B)   Bicol Express        Php 700.00	   (E)   Kare-Kare	Php 1000.00"<<endl;
cout<<"(C)   Beef Steak		 Php 800.00"<<endl;
cout<<"Rices:"<<endl;
cout<<"(F)   Plain		 Php 10.00	   (I)   Japanese	Php 18.00"<<endl;
cout<<"(G)   Fried		 Php 12.00	   (J)   Yang Chow      Php 25.00"<<endl;
cout<<"(H)   Brown		 Php 15.00"<<endl;
cout<<"Desserts:"<<endl;
cout<<"(K)   Ice Cream		 Php 30.00	   (N)	 Dried Mango    Php 45.00"<<endl;
cout<<"(L)   Halo-Halo		 Php 35.00         (O)   Leche Flan     Php 50.00"<<endl;
cout<<"(M)   Chocolate		 Php 40.00"<<endl;
cout<<"Drinks:"<<endl;
cout<<"(P)   Mineral Water	 Php 10.00         (S)   Gatorade       Php 26.00"<<endl;
cout<<"(Q)   Pepsi in Can	 Php 25.00         (T)   Monster Enery  Php 90.00"<<endl;
cout<<"(R)   Cocacola in Can	 Php 28.00"<<endl;
cout<<"Liquors:"<<endl;
cout<<"(U)   Emperador Lights    Php 110.00        (X)   Emperador Deluxe Php 300.00"<<endl;
cout<<"(V)   Red Horse Jumbo     Php 80.00         (Y)   OR.GY Lambanog  Php  100.00"<<endl;
cout<<"(W)   Black Label         Php 1555.00       (Z)   Jack Daniels     Php 2015.00"<<endl;

cout<<"What is Your Order?"<<endl;
cin>>order;

switch(order)
{
case 'a': case 'A':
cout<<"You Ordered Sweet and Sour Pork";
price=600;
break;
case 'b': case 'B':
cout<<"You Ordered Bicol Express";
price=700;
break;
case 'c': case 'C':
cout<<"You Ordered Beef Steak";
price=800;
break;
case 'd': case 'D':
cout<<"You Ordered Pigar-Pigar";
price=900;
break;
case 'e': case 'E':
cout<<"You Ordered Kare-Kare";
price=1000;
break;
case 'f': case 'F':
cout<<"You Ordered Plain Rice";
price=10;
break;
case 'g': case 'G':
cout<<"You Ordered Fried Rice";
price=12;
break;
case 'h': case 'H':
cout<<"You Ordered Brown Rice";
price=15;
break;
case 'i': case 'I':
cout<<"You Ordered Japanese Rice";
price=18;
break;
case 'j': case 'J':
cout<<"You Ordered Yang Chow Rice";
price=25;
break;
case 'k': case 'K':
cout<<"You Ordered Ice Cream";
price=30;
break;
case 'l': case 'L':
cout<<"You Ordered Halo-Halo";
price=35;
break;
case 'm': case 'M':
cout<<"You Ordered Chocolate";
price=40;
break;
case 'n': case 'N':
cout<<"You Ordered Dried Mango";
price=45;
break;
case 'o': case 'O':
cout<<"You Ordered Leche Flan";
price=50;
break;
case 'p': case 'P':
cout<<"You Ordered Mineral Water";
price=10;
break;
case 'q': case 'Q':
cout<<"You Ordered Pepsi in Can";
price=25;
break;
case 'r': case 'R':
cout<<"You Ordered Cocacola in Can";
price=28;
break;
case 's': case 'S':
cout<<"You Ordered Red Horse Beer (1 liter)";
price=80;
break;
case 't': case 'T':
cout<<"You Ordered Red Horse Beer (500 ml)";
price=40;
break;
case 'u': case 'U':
cout<<"You Ordered Emperador Lights";
price=110;
break;
case 'v': case 'V':
cout<<"You Ordered Emperador Deluxe";
price=300;
break;
case 'W': case 'w':
cout<<"You Ordered Red Horse Jumbo";
price=80;
break;
case 'x': case 'X':
cout<<"You Ordered OR.GY Lambanog";
price=100;
break;
case 'y': case 'Y':
cout<<"You Ordered Black Label";
price=1555;
break;
case 'z': case 'Z':
cout<<"You Ordered JACK DANIELS";
price=2015;
break;
default:
cout<<"Invalid Entry, Please Restart.";
break;
}

cout<<"           How Many Order/s?"<<endl;
cin>>quota;
bill+=price*quota;
cout<<"Your Total bill is Php  "<<bill<<endl;
cout<<"Order Again? Y/N"<<endl;
cin>>loop;

}while(loop=='Y'||loop=='y');
if (loop=='N' ||loop=='n')
{

total=bill*0.06;
tbill=total+bill;
cout<<"Your Bill is Php  "<<bill;
cout<<" + Service Charge (6%) of your bill is Php  "<<total<<endl;
cout<<"Your Total Bill is Php  "<<tbill<<endl;
cout<<" THANK YOU VERY MUCH! "<<endl;
}
else
{
cout<<"Invalid Choice, Please Restart";

}


getch();
return 0;
}
Topic archived. No new replies allowed.