Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*#include <stdio.h>
- #include <string.h>
- int main()
- {
- int num_guests, num_chairs = 0, num_tables = 0, num_cups = 0, num_dishes = 0;
- float chair_price = 13.99, table_price = 42.00, cups_price = 5.98, dishes_price = 21.02;
- char item[10];
- scanf("Enter the amount of the guest: %d", &num_guests);
- while (strcmp(item, "PARTY!") != 0)
- {
- scanf("%s", item);
- if (strcmp(item, "Chair") == 0)
- {
- num_chairs++;
- } else if (strcmp(item, "Table") == 0)
- {
- num_tables++;
- } else if (strcmp(item, "Cups") == 0)
- {
- num_cups += 6;
- } else if (strcmp(item, "Dishes") == 0)
- {
- num_dishes += 6;
- }
- }
- float total_cost = num_chairs * chair_price + num_tables * table_price +
- (num_cups / 6) * cups_price + (num_dishes / 6) * dishes_price;
- int needed_chairs = num_guests - num_chairs;
- int needed_tables = (needed_chairs <= 0) ? 0 : (needed_chairs + 7) / 8;
- int needed_cups = num_guests - num_cups;
- int needed_dishes = num_guests - num_dishes;
- printf("%.2f\n", total_cost);
- printf("%d Table(s)\n%d Chair(s)\n%d Dishes set(s)\n", needed_tables, needed_chairs, needed_dishes);
- if (needed_cups > 0)
- {
- printf("1 more Cups set(s)\n");
- }
- return 0;
- }*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX_PRODUCTS 1000
- #define MAX_ORDERS 1000
- typedef struct
- {
- char name[50];
- double price;
- int id;
- } Product;
- typedef struct
- {
- char address[100];
- int product_id;
- } Order;
- int main()
- {
- Product products[MAX_PRODUCTS];
- Order orders[MAX_ORDERS];
- int num_products = 0, num_orders = 0;
- char input[100];
- while (1)
- {
- fgets(input, sizeof(input), stdin);
- if (strncmp(input, "Product", 7) == 0)
- {
- Product p;
- printf("Product name: ");
- fgets(p.name, sizeof(p.name), stdin);
- printf("Price: ");
- scanf("%lf", &p.price);
- getchar();
- p.id = num_products + 1;
- products[num_products++] = p;
- int i;
- for (i = 0; i < num_orders; i++)
- {
- if (orders[i].product_id == p.id)
- {
- printf("Client %s ordered %s\n", orders[i].address, p.name);
- orders[i] = orders[--num_orders];
- i--;
- }
- }
- }
- else if (strncmp(input, "Order", 5) == 0)
- {
- Order o;
- printf("Address: ");
- fgets(o.address, sizeof(o.address), stdin);
- printf("Product ID: ");
- scanf("%d", &o.product_id);
- getchar();
- orders[num_orders++] = o;
- int i;
- for (i = 0; i < num_products; i++)
- {
- if (products[i].id == o.product_id)
- {
- printf("Client %s ordered %s\n", o.address, products[i].name);
- orders[--num_orders] = orders[--num_orders];
- break;
- }
- }
- }
- else if (strncmp(input, "END", 3) == 0)
- {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment