Untitled
unknown
plain_text
20 days ago
4.2 kB
1
Indexable
Never
#include <stdio.h> int main() { char items[15][107]; int item_code[15]; int quantity[15]; int last_item_index = 0; while (1) { printf("--- Inventory Management System ---\n"); printf("1. Add Items\n"); printf("2. Display All Items\n"); printf("3. Search for an Item\n"); printf("4. Update Item Quantity\n"); printf("5. Find the Item with the lowest Quantity\n"); printf("6. Exit\n"); printf("Enter your choice: "); int choice, flag; scanf("%d", &choice); switch (choice) { case 1: if (last_item_index >= 15) { printf("You can't add more products!\n"); printf("\n"); break; } fflush(stdin); printf("Enter the name of the item: "); scanf("%s", items[last_item_index]); printf("Enter the item code: "); scanf("%d", &item_code[last_item_index]); printf("Enter the quantity: "); scanf("%d", &quantity[last_item_index]); last_item_index++; printf("\n"); break; case 2: if (last_item_index <= 0) { printf("No product available!\n"); printf("\n"); break; } for (int i = 0; i < last_item_index; i++) { printf("Name: %s, Item code: %d, Quantity: %d\n", items[i], item_code[i], quantity[i]); } printf("\n"); break; case 3: printf("Enter item code to search: "); int search_item_code; scanf("%d", &search_item_code); flag = 0; for (int i = 0; i < last_item_index; i++) { if (item_code[i] == search_item_code) { flag = 1; printf("Item found: "); printf("Name: %s, Item code: %d, Quantity: %d\n", items[i], item_code[i], quantity[i]); printf("\n"); break; } } if (flag == 0) { printf("Item not found!\n"); } printf("\n"); break; case 4: printf("Enter item code to update: "); int update_item_code; scanf("%d", &update_item_code); flag = 0; for (int i = 0; i < last_item_index; i++) { if (item_code[i] == search_item_code) { printf("Enter new quantity: "); int new_quantity; scanf("%d", &new_quantity); quantity[i] = new_quantity; printf("\n"); flag = 1; break; } } if (flag == 0) { printf("Item not found!\n"); } printf("\n"); break; case 5: if (last_item_index <= 0) { printf("No product available!\n"); printf("\n"); break; } int lowest_quantity = quantity[0], lowest_quantity_index = 0; for (int i = 1; i < last_item_index; i++) { if (quantity[i] < lowest_quantity) { lowest_quantity = quantity[i]; lowest_quantity_index = i; } } printf("Item with lowest quantity: "); printf("Name: %s, Item code: %d, Quantity: %d\n", items[lowest_quantity_index], item_code[lowest_quantity_index], quantity[lowest_quantity_index]); printf("\n"); break; case 6: printf("Exiting the program...\n\n"); return 0; default: break; } } }
Leave a Comment