-
Notifications
You must be signed in to change notification settings - Fork 0
/
pizzaOrder.c
141 lines (129 loc) · 2.44 KB
/
pizzaOrder.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
#include <stdio.h>
#include <stdbool.h>
#define INVALID_INPUT -404
#define INVALID_charIn 'X'
int inputPizzaType()
{
int type;
printf("Input pizza type : ");
if(scanf("%i",&type)!=1)
{
printf("Invalid Pizza Type !!\n");
while(getchar() == '\n');
type = INVALID_INPUT;
}
else if (type != 1 && type != 2 && type != -1)
{
type = INVALID_INPUT;
printf("Invalid Pizza Type !!\n");
}
return type;
}
char inputPizzaSize()
{
char size;
printf("Input the pizza size : ");
scanf(" %c",&size);
switch (size)
{
case 'L':
size = 'L';
break;
case 'l':
size = 'L';
break;
case 'M':
size = 'M';
break;
case 'm':
size = 'M';
break;
default :
printf("Invalid Pizza Size !!\n");
size = INVALID_charIn;
break;
}
return size;
}
int inputPizzaQty()
{
int qty;
printf("Input the number of pizzas : ");
if(scanf("%i",&qty)!=1)
{
printf("Invalid Pizza Qty !!\n");
while(getchar() == '\n');
qty = INVALID_INPUT;
}
return qty;
}
char inputYN(char *msg)
{
char input;
printf(msg);
scanf(" %c",&input);
switch (input)
{
case 'Y':
input = 'Y';
break;
case 'y':
input = 'Y';
break;
case 'N':
input = 'N';
break;
case 'n':
input = 'N';
break;
default :
printf("Invalid Input !!\n");
input = INVALID_charIn;
}
return input;
}
int main(void)
{
int type,qty;
char size,paymentType,customerType,orderType;
float total,discount,netAmount,price;
do
{
while ((type = inputPizzaType()) == INVALID_INPUT);
if(type == -1)
break;
while ((size = inputPizzaSize()) == INVALID_charIn);
while ((qty = inputPizzaQty()) == INVALID_INPUT);
switch(type)
{
case 1:
if (size == 'L')
price = 1720.00;
else
price = 975.00;
break;
case 2:
if (size == 'L')
price = 1820.00;
else
price = 1000.00;
break;
}
total += price * qty;
printf("\n");
}while(true);
while((paymentType = inputYN("\n\nAre you paying by credit card (Y/N) ? ")) == INVALID_charIn);
while((customerType = inputYN("Are you a loyalty customer (Y/N)? ")) == INVALID_charIn);
while((orderType = inputYN("Is this an online order (Y/N)? ")) == INVALID_charIn);
if (paymentType == 'Y')
discount += total *0.2;
if (customerType == 'Y')
discount += total * 0.15;
if (orderType == 'Y')
discount += total * 0.05;
netAmount = total - discount ;
printf("\n\nTotal bill amount: %.2f\n",total);
printf("Discount: %.2f\n",discount);
printf("Net Amount: %.2f\n",netAmount);
return 0;
}