I need this to add 2% discount in Pizza Price if it Increase RS.5000

Menu Base Program
Press B for BBQ Pizza
Press S for Smoke Pizza
than ask for small pizza or large pizaa
than add quantity
than if price exceed 5000 than give 2% Discoubt


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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
  #include <iostream>

using namespace std;
int main()
{
	char choice,secchoice;
	int quty;
	cout<<"Press B for BBQ Pizza "<<endl;
	cout<<"Press S for Smoked Pizza "<<endl;
	cout<<"Press G for grilled Pizza "<<endl;
	cout<<"press M for Marconi and cheese "<<endl;
	cout<<"press C for Cantaloupe "<<endl;
	cout<<"press L for Butter lobster "<<endl;
	cout<<"press Z for zucchini "<<endl;

	cin>>choice;
	if(choice=='B'||choice=='b')
	{
		cout<<"Press S for small (500) "<<endl;
		cout<<"Press M for Medium (800) "<<endl;
		cout<<"Press L for Large (1100) "<<endl;
		cout<<"Press X Extra large (1600) "<<endl;
	
	cin>>secchoice;
		switch (secchoice)
		{
		case 'S':
		case 's':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*500<<endl;
			break;
			case 'M':
		case 'm':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*800<<endl;
			break;
			case 'L':
		    case 'l':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1100<<endl;
			break;
			case 'X':
		case 'x':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1600<<endl;
			break;
		default:
			cout<<"Invalid";
			break;
		}
	}
	if(choice=='S'||choice=='s')
	{
		cout<<"Press S for small (550) "<<endl;
		cout<<"Press M for Medium (850) "<<endl;
		cout<<"Press L for Large (1150) "<<endl;
		cout<<"Press X Extra large (1650) "<<endl;
	
	    cin>>secchoice;
		switch (secchoice)
		{
		case 'S':
		case 's':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*550<<endl;
			break;
			case 'M':
		case 'm':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*850<<endl;
			break;
			case 'L':
		    case 'l':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1150<<endl;
			break;
			case 'X':
		case 'x':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1650<<endl;
			break;
		default:
			cout<<"Invalid";
			break;
		}
    }
	
	if(choice=='G'||choice=='g')
	{
		cout<<"Press S for small (600) "<<endl;
		cout<<"Press M for Medium (900) "<<endl;
		cout<<"Press L for Large (1300) "<<endl;
		cout<<"Press X Extra large (1900) "<<endl;
	
	cin>>secchoice;
		switch (secchoice)
		{
		case 'S':
		case 's':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*600<<endl;
			break;
			case 'M':
		case 'm':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*900<<endl;
			break;
			case 'L':
		    case 'l':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1300<<endl;
			break;
			case 'X':
		case 'x':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1900<<endl;
			break;
		default:
			cout<<"Invalid";
			break;
	    }
    }
	if(choice=='M'||choice=='m')
	{
		cout<<"Press S for small (750) "<<endl;
		cout<<"Press M for Medium (950) "<<endl;
		cout<<"Press L for Large (1050) "<<endl;
		cout<<"Press X Extra large (1850) "<<endl;
	
	cin>>secchoice;
		switch (secchoice)
		{
		case 's':
		case 'S':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*750<<endl;
			break;
			case 'M':
		    case 'm':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*950<<endl;
			break;
			case 'L':
		    case 'l':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1050<<endl;
			break;
			case 'X':
		case 'x':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1850<<endl;
			break;
		default:
			cout<<"Invalid";
			break;
		}
   }
	if(choice=='C'||choice=='c')
	{
		cout<<"Press S for small (800) "<<endl;
		cout<<"Press M for Medium (980) "<<endl;
		cout<<"Press L for Large (1100) "<<endl;
		cout<<"Press X Extra large (2000) "<<endl;
	
	cin>>secchoice;
		switch (secchoice)
		{
		case 'S':
		case 's':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*800<<endl;
			break;
			case 'M':
		    case 'm':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*980<<endl;
			break;
			case 'L':
		    case 'l':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1100<<endl;
			break;
			case 'X':
		case 'x':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*2000<<endl;
			break;
		default:
			cout<<"Invalid";
			break;
		}
	}
    if(choice=='L'||choice=='l')
	{
		cout<<"Press S for small (450) "<<endl;
		cout<<"Press M for Medium (1000) "<<endl;
		cout<<"Press L for Large (1200) "<<endl;
		cout<<"Press X Extra large (1600) "<<endl;
	
	cin>>secchoice;
		switch (secchoice)
		{
		case 'S':
		case 's':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*450<<endl;
			break;
			case 'M':
		    case 'm':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1000<<endl;
			break;
			case 'L':
		    case 'l':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1200<<endl;
			break;
			case 'X':
		case 'x':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1600<<endl;
			break;
		default:
			cout<<"Invalid";
			break;
		}
	}
	if(choice=='Z'||choice=='z')
	{
		cout<<"Press S for small (500) "<<endl;
		cout<<"Press M for Medium (800) "<<endl;
		cout<<"Press L for Large (1100) "<<endl;
		cout<<"Press X Extra large (2050) "<<endl;
	
	cin>>secchoice;
		switch (secchoice)
		{
		case 'S':
		case 's':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*500<<endl;
			break;
			case 'M':
		    case 'm':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*800<<endl;
			break;
			case 'L':
		    case 'l':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*1100<<endl;
			break;
			case 'X':
		case 'x':
			cout<<"Enter quantity ";
			cin>>quty;
			cout<<"Bill "<<quty*2050<<endl;
			break;
		default:
			cout<<"Invalid";
			break;
		}
	}
    system ("pause");
}
Hello Faizts,

Watch your indenting. You have some case statements indented to far. Not a problem for the compiler, but it does make it harder to read and follow.

Your program would benefit from putting a lot of the repeated code in a function or two.

Working with what you have I would change the beginning of "main" to something like this:
1
2
3
4
5
6
7
int main()
{
	constexpr double DISCOUNT{ 0.02 };

        double discount{};
	char choice, secchoice;
	int quty, subTotal{};


From line 56 on I would change the if statements to "else if" statements. Then at line 291 insert an else statement to deal with an invalid entry.

All the lines cout<<"Bill "<<quty*800<<endl; would work better as subTotal = quty * price; Where price is what you currently have in each section.

After the else statement put:
1
2
3
4
5
6
7
8
9
10
11
if (subTotal >5000)
{
    discount=subTotal * DISCOUNT;

    // cout statements to display
    //  subTotal
    // - discount
    // total
}
else
    // display subTotal 


I have not changed everything yet to try it, but the concept is good.

Almost forgot. Include the header file "cctype" Then in the if and else if statements you can use
if( std::toupper(choice) == 'B' etc. then you would not have to check for lower case letters. Or you could follow the "cin" statement with the "toupper()". The same applies to switch (secchoice). It does save you from checking for either case.

Hope that helps,

Andy
Maybe it would also be easier to have all of the prices defined in one place, and to use two or three small functions to do some of the stuff, rather than to repeat much of the code. The code below is definitely not meant to be perfect, but just an idea for how you might want to clean one or two things if you chose to:

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
#include <iostream>
using namespace std;

void print_menu(){
    cout << "Press B for BBQ Pizza " << endl;
    cout << "Press S for Smoked Pizza " << endl;
    cout << "Press G for grilled Pizza " << endl;
    // other options to be entered below
}

void print_menu2(int *pz){
    cout<<"Press S for small (" << pz[0] << ") "<< endl;
    cout<<"Press M for Medium (" << pz[1] << ") "<< endl;
    cout<<"Press L for Large (" << pz[2] << ") "<< endl;
    cout<<"Press X Extra large (" << pz[3] << ") "<< endl;
}

void second_choice(char &secchoice){
    cin >> secchoice;
    secchoice=toupper(secchoice);
}

float calc_bill(int quantity, int price){
    float bill = quantity * price;
    if (bill > 5000)
    {
    // deduct 2%   
    }
return bill;
}

void provide_bill(int *pz, char psize, int quty){
    switch (psize) {
     case 'S':
            cout << "Bill " << calc_bill(quty, pz[0]) << endl;
            break;
     case 'M':
	    cout << "Bill " << calc_bill(quty, pz[1]) << endl;
	    break;
     case 'L':
	    cout << "Bill " << calc_bill(quty, pz[2]) << endl;
	    break;
    case 'X':
	    cout << "Bill " << calc_bill(quty, pz[3]) << endl;
	    break;
    default:
	    cout << "Huh? Invalid";
	    break;
   }   
}

int get_quantity(){
    int num_pizzas;
    cout << "Enter quantity ";
    cin >> num_pizzas;
return num_pizzas;
}

int main() {

    int pizzaB[4]={500,800,1100,1600};
    int pizzaS[4]={550,850,1150,1650};
    int pizzaG[4]={600,900,1300,1900};
    int pizzaM[4]={};                   // prices to be entered for pizzaM
    int pizzaC[4]={};                   //  "   "               for pizzaC
    int pizzaL[4]={};                   //  "   "               for pizzaL
    int pizzaZ[4]={};                   //  "   "               for pizzaZ

    char choice, secchoice;
    int quantity=0;

    print_menu();
    cin >> choice;
    choice = toupper(choice);

    if(choice=='B')           // Pizza B
    {
    print_menu2(pizzaB);
    second_choice(secchoice);
    quantity=get_quantity();
    provide_bill(pizzaB,secchoice,quantity);
    }
    else if(choice=='S')     // Pizza S
    {
    print_menu2(pizzaS);
    second_choice(secchoice);
    quantity=get_quantity();
    provide_bill(pizzaS,secchoice,quantity);    
    }
    else if(choice=='G')     // Pizza G
    {
    print_menu2(pizzaG);
    second_choice(secchoice);
    quantity=get_quantity();
    provide_bill(pizzaG,secchoice,quantity);    
    }

    // removed other pizza options for brevity .... 
    
    // other options below ...

return 0;
}

I'm sure there are many improvements could be made to the code above, but hope it might help you just a little maybe.
Last edited on
Hello Faizts,

I made the changes I suggested and it works. I also made some other adjustments so the display would look better.

As an example:
1
2
3
4
5
6
7
8
9
10
std::cout << "\nPress B for BBQ Pizza";
std::cout << "\nPress S for Smoked Pizza";
std::cout << "\nPress G for grilled Pizza";
std::cout << "\npress M for Marconi and cheese";
std::cout << "\npress C for Cantaloupe";
std::cout << "\npress L for Butter lobster";
std::cout << "\npress Z for zucchini" << std::endl;

std::cout << " Enter choice: ";
std::cin >> choice;

Putting the "\n" at the beginning of the line puts each choice on its own line. The "endl" on the last line flushes the output buffer and makes sure everything is sent to the screen. In the last two lines ending the "cout" with just a ";" allows the "cin" to be on the same line. The output look like this instead of everything being on one line:

Press B for BBQ Pizza
Press S for Smoked Pizza
Press G for grilled Pizza
press M for Marconi and cheese
press C for Cantaloupe
press L for Butter lobster
press Z for zucchini
 Enter choice: b

Press S for small (500)
Press M for Medium (800)
Press L for Large (1100)
Press X Extra large (1600)
 Enter choice: x

Enter quantity: 4

 Subtotal  6400
 Discount   128
    Total  6272


Press any key to continue . . .



And for the final part I did this:
1
2
3
4
5
6
7
8
9
if (subTotal > 5000)
{
	discount = subTotal * DISCOUNT;
	std::cout << "\n" << std::setw(10) << "Subtotal " << std::setw(5) << subTotal;
	std::cout << "\n" << std::setw(10) << "Discount " << std::setw(5) << discount;
	std::cout << "\n" << std::setw(10) << "Total " << std::setw(5) << subTotal - discount << "\n\n" << std::endl;
}
else
	std::cout << "\n  " << "Subtotal " << subTotal << '\n' << std::endl;

I allowed for the numbers to be for 10,000 or above.

To use "setw" you will need the header file "iomanip".

Hope that helps,

Andy
Thanks to all of you for your support
so much response thanks guys
Topic archived. No new replies allowed.