-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcashier.c
59 lines (49 loc) · 1.27 KB
/
cashier.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
#include <stdio.h>
#include <string.h>
int main(void)
{
//* Declaring and initializing the variables.
int age = 0;
int milk = 0;
int total_price = 0;
// * Get age.
printf("Age: \n");
scanf("%i", &age);
// * Get number of items.
printf("number of items: \n");
int total_items = 0;
scanf("%i", &total_items);
int prices[total_items];
// * Getting the name and price of each item.
for (int i = 0; i < total_items; i++)
{
char item[20];
int price = 0;
int num = i + 1;
printf("Item %i : \n", num);
printf("Item name : \n");
scanf("%s", &item);
//* Checking if the item is milk. If it is, it will increment the milk variable.
int is_milk = strcmp(item,"milk");
if(is_milk == 0){
milk++;
}
printf("Item price : \n");
scanf("%i", &price);
prices[i] = price;
}
// * Calculate total price.
for (int i = 0; i < total_items; i++)
{
total_price += prices[i];
}
// * Checking if the customer has qualified for a 5% discount.
if(age >= 70 && total_items>= 3 && total_price >= 1000 && milk)
{
int discount = total_price * 0.95;
printf("Discount: 5%%\n");
printf("Total: %i\n",discount);
}else{
printf("Total: %i\n",total_price);
}
}