-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
221 lines (190 loc) · 5.98 KB
/
main.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
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
/*
Project 45 - Solution for J3 Snack Bar
Description
This program calculates how much each customer spends in a snack bar.
In essence, this program initializes 3 matrices:
p[1][7] - Price of the Snack bar Products
q[7][1] - Quantity of each item asked
t[1][7] - Total price to pay
Then, Make the math matrices multiplication:
p[1][7] * q[7][1] = t[1][7]
_ _ _ _
| 5.00 | | 5.00 |
| 8.79 | | 8.79 |
| 9.99 | * [1,1,1,1,1,1,1] = | 9.99 |
| 6.89 | | 6.89 |
| 4.80 | | 4.80 |
| 3.49 | | 3.49 |
|_ 4.99_| |_ 4.99_|
Total = $ 43.95
Other matrices, like 'seq', 'code' and 'menu' serves only for presentation purpose;
The user enter Code + Product + Space serially; The user can acummulate the products;
When done, type 'q' to get the Receipt;
It is for the academy's elegant solution of Project 31:)
Printing on the screen a test of the program using
the first 3 digits for products and
the last 3 digits for quantity of the RU identifier:
***********************
Output: (RU 333 6 662)
-------------------------------
:::::::JayThree Snack Bar::::::
Welcome!!
-------------------------------
--------------MENU-------------
Code Product Price
-------------------------------
1 Hot_Dog 5.00
2 X_Salad 8.79
3 X_Bacon 9.99
4 Mix 6.89
5 Salad 4.80
6 Water 3.49
7 Soda 4.99
-------------------------------
Please Choose your Combo:)
Type:Code>Space>Quant>Enter:
To Quit, type 'q':)
3 6
You chose: 6 x X-Bacon
3 6
You chose: 6 x X-Bacon
3 2
You chose: 2 x X-Bacon
q
Good Choice!
Here you have the ticket:
___________Receipt:____________
Quant Price Product Total
-------------------------------
14 x 9.99 X_Bacon 139.86
-------------------------------
Total = 139.86
-------------------------------
Thank you for your visit
and have a good appetite!
***********************
Editor J3
Date: Jul, 15/2020
I'd like to thank Prof. Borin, Me.(https://br.linkedin.com/in/borinvini)
o/
*/
#include <stdio.h>
int main()
{
int seq[1][7] = {1, 2, 3, 4, 5, 6, 7};
int code[1][7] = {100, 101, 102, 103, 104, 105, 106};
char menu[7][10] = { "Hot_Dog", "X_Salad", "X_Bacon", "Mix", "Salad", "Water", "Soda" };
float p[1][7] = {5.00, 8.79, 9.99, 6.89, 4.80, 3.49, 4.99}, t[1][7] = {0}, debit;
int q[7][1] = {0,0,0,0,0,0,0};
int prows = 1, pcolumns = 7, qrows = 7, qcolumns = 1, trows = 1, tcolumns = 7;
int i,j,k;
float res = 0, sum = 0;
int prod = 0;
int quant = 0;
/* Menu on screen splash */
printf("\n-------------------------------");
printf("\n:::::::JayThree Snack Bar::::::");
printf("\n\t Welcome!!");
printf("\n-------------------------------");
printf("\n--------------MENU-------------\n");
printf("Code\tProduct\t\tPrice\n");
printf("-------------------------------\n");
for(int i = 0; i < 1; i++)
{
for(int j=0; j < 7; j++)
{
printf("%i\t", seq[i][j]);
printf("%s\t\t", menu[j] );
printf("%.2f\t\n", p[i][j] );
}
printf("-------------------------------");
}
printf("\n\nPlease Choose your Combo:)\nType:Code>Space>Quant>Enter:\n");
printf("To Quit, type 'q':)\n");
scanf("%i %i", &prod, &quant);
/* Populating 'q' matrix - quantity of each product indexed */
/* While loop exit by typing 'q' - Quit */
/* Product can be acummulated in a single bid */
while(getchar()!= 'q')
{
switch (prod)
{
case 1:
printf("You chose: %d x Hot Dog\n", quant);
q[0][0] += quant;
break;
case 2:
printf("You chose: %d x X-Salad\n", quant);
q[1][0] += quant;
break;
case 3:
printf("You chose: %d x X-Bacon\n", quant);
q[2][0] += quant;
break;
case 4:
printf("You chose: %d x Mix\n", quant);
q[3][0] += quant;
break;
case 5:
printf ("You chose: %d x Salad\n", quant);
q[4][0] += quant;
break;
case 6:
printf ("You chose: %d x Water\n", quant);
q[5][0] += quant;
break;
case 7:
printf ("You chose: %d x Soda\n", quant);
q[6][0] += quant;
break;
default:
printf("Invalid Product:/\n");
break;
}
scanf("%i %i", &prod, &quant);
}
printf("\tGood Choice!\n");
/* Calculating all 't' matrix - total to pay = debit */
int m = 0;
for (i=0; i<prows; i++)
{
for(j=0; j<qcolumns; j++)
{
for(k=0; k<qrows; k++)
{
res += p[i][k] * q[k][j];
t[i][m] = res;
m++;
sum += res;
res = 0;
}
debit = sum;
sum = 0;
}
}
/* Printing the receipt - print when there is value on 't' index */
printf ("\n Here you have the ticket:\n\n");
printf("___________Receipt:____________\n");
printf("Quant\tPrice\tProduct\tTotal\n");
printf("-------------------------------\n");
for( i=0; i<trows; i++ )
{
for(j=0; j<tcolumns; j++)
{
if( t[i][j] != 0)
{
printf("%d x\t", q[i][j]);
printf("%.2f\t", p[i][j]);
printf("%s\t", menu[j] );
printf("%.2f\t\n", t[i][j]);
}
}
printf("-------------------------------\n");
printf("\t\tTotal = %.2f\t", debit);
printf("\t\t\n-------------------------------");
printf("\t\t\n");
}
printf("\nThank you for your visit\nand have a good appetite!\n");
//system("pause");
return 0;
}