Radoslav_03

Untitled

May 2nd, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. /*#include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6. int num_guests, num_chairs = 0, num_tables = 0, num_cups = 0, num_dishes = 0;
  7. float chair_price = 13.99, table_price = 42.00, cups_price = 5.98, dishes_price = 21.02;
  8.  
  9. char item[10];
  10.  
  11. scanf("Enter the amount of the guest: %d", &num_guests);
  12.  
  13. while (strcmp(item, "PARTY!") != 0)
  14. {
  15. scanf("%s", item);
  16. if (strcmp(item, "Chair") == 0)
  17. {
  18. num_chairs++;
  19. } else if (strcmp(item, "Table") == 0)
  20. {
  21. num_tables++;
  22. } else if (strcmp(item, "Cups") == 0)
  23. {
  24. num_cups += 6;
  25. } else if (strcmp(item, "Dishes") == 0)
  26. {
  27. num_dishes += 6;
  28. }
  29. }
  30.  
  31. float total_cost = num_chairs * chair_price + num_tables * table_price +
  32. (num_cups / 6) * cups_price + (num_dishes / 6) * dishes_price;
  33.  
  34. int needed_chairs = num_guests - num_chairs;
  35. int needed_tables = (needed_chairs <= 0) ? 0 : (needed_chairs + 7) / 8;
  36. int needed_cups = num_guests - num_cups;
  37. int needed_dishes = num_guests - num_dishes;
  38.  
  39. printf("%.2f\n", total_cost);
  40. printf("%d Table(s)\n%d Chair(s)\n%d Dishes set(s)\n", needed_tables, needed_chairs, needed_dishes);
  41. if (needed_cups > 0)
  42. {
  43. printf("1 more Cups set(s)\n");
  44. }
  45.  
  46. return 0;
  47. }*/
  48.  
  49.  
  50.  
  51.  
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54. #include <string.h>
  55.  
  56. #define MAX_PRODUCTS 1000
  57. #define MAX_ORDERS 1000
  58.  
  59. typedef struct
  60. {
  61. char name[50];
  62. double price;
  63. int id;
  64. } Product;
  65.  
  66. typedef struct
  67. {
  68. char address[100];
  69. int product_id;
  70. } Order;
  71.  
  72. int main()
  73. {
  74. Product products[MAX_PRODUCTS];
  75. Order orders[MAX_ORDERS];
  76. int num_products = 0, num_orders = 0;
  77. char input[100];
  78.  
  79. while (1)
  80. {
  81. fgets(input, sizeof(input), stdin);
  82.  
  83. if (strncmp(input, "Product", 7) == 0)
  84. {
  85.  
  86. Product p;
  87. printf("Product name: ");
  88. fgets(p.name, sizeof(p.name), stdin);
  89. printf("Price: ");
  90. scanf("%lf", &p.price);
  91. getchar();
  92. p.id = num_products + 1;
  93. products[num_products++] = p;
  94.  
  95.  
  96. int i;
  97. for (i = 0; i < num_orders; i++)
  98. {
  99. if (orders[i].product_id == p.id)
  100. {
  101. printf("Client %s ordered %s\n", orders[i].address, p.name);
  102. orders[i] = orders[--num_orders];
  103. i--;
  104. }
  105. }
  106. }
  107. else if (strncmp(input, "Order", 5) == 0)
  108. {
  109.  
  110. Order o;
  111. printf("Address: ");
  112. fgets(o.address, sizeof(o.address), stdin);
  113. printf("Product ID: ");
  114. scanf("%d", &o.product_id);
  115. getchar();
  116. orders[num_orders++] = o;
  117.  
  118.  
  119. int i;
  120. for (i = 0; i < num_products; i++)
  121. {
  122. if (products[i].id == o.product_id)
  123. {
  124. printf("Client %s ordered %s\n", o.address, products[i].name);
  125. orders[--num_orders] = orders[--num_orders];
  126. break;
  127. }
  128. }
  129. }
  130. else if (strncmp(input, "END", 3) == 0)
  131. {
  132. break;
  133. }
  134. }
  135.  
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment