What could be the problem

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. and if you are in the 1st loop if you put invalid input it'll forever loop, btw, this is turbo c

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
178
#include<conio.h>
#include<iostream.h>

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

main()
{
do
{
clrscr();
cout<<"-------------Raii's 24/7 Place------------"<<endl;
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<<"Beverages:"<<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;
}

cout<<"\n\nHow Many Order/s?"<<endl;
cin>>quota;
bill+=price*quota;
bill1=price*quota;
cout<<"You Ordered  "<<quota;
cout<<" pc/s * Php  "<<price<<" = "<<bill1<<endl;

cout<<"\nYour Current Bill is Php  "<<bill<<endl;
cout<<"\nOrder 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<<" + Service Charge (6%) of your bill is Php  "<<total<<endl;
cout<<"\nYour Total Bill is Php  "<<tbill<<endl;
cout<<"\n  THANK YOU VERY MUCH!! "<<endl;
cout<<endl;
cout<<"by:  R a i i "<<endl;
}
else
{
cout<<"Invalid Choice, Please Restart.";
}
getch();
return 0;
}
Last edited on
A simple goto statement would save you lines.. I like goto very much but it should be used carefully.... Anyways here's the code

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
178
179
180
181
182
183
#include<conio.h>
#include<iostream.h>

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

main()
{
do
{
clrscr();
cout<<"-------------Raii's 24/7 Place------------"<<endl;
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<<"Beverages:"<<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:
goto again;
}

cout<<"\n\nHow Many Order/s?"<<endl;
cin>>quota;
bill+=price*quota;
bill1=price*quota;
cout<<"You Ordered  "<<quota;
cout<<" pc/s * Php  "<<price<<" = "<<bill1<<endl;

cout<<"\nYour Current Bill is Php  "<<bill<<endl;
cout<<"\nOrder 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<<" + Service Charge (6%) of your bill is Php  "<<total<<endl;
cout<<"\nYour Total Bill is Php  "<<tbill<<endl;
cout<<"\n  THANK YOU VERY MUCH!! "<<endl;
cout<<endl;
cout<<"by:  R a i i "<<endl;
}
else
{
again:  //smartly placed....
cout<<"Invalid Choice, Please Restart.";
}
getch();
return 0;
}

//PS try some other compiler not many people use turbo c++ :D 


Last edited on
Topic archived. No new replies allowed.