C语言实现超实用体育用品销售管理系统代码全解析
```c #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { char name[50]; int quantity; float price; } Product; void addProduct(Product *products, int *count); void displayProducts(Product *products, int count); void sellProduct(Product *products, int count); int main() { Product products[100]; int count = 0; int choice; while (1) { printf("体育用品销售管理系统 "); printf("1. 添加产品 "); printf("2. 显示所有产品 "); printf("3. 销售产品 "); printf("4. 退出 "); printf("请输入您的选择: "); scanf("%d", &choice); switch (choice) { case 1: addProduct(products, &count); break; case 2: displayProducts(products, count); break; case 3: sellProduct(products, count); break; case 4: exit(0); default: printf("无效的选择,请重新输入。 "); } } return 0; } void addProduct(Product *products, int *count) { printf("请输入产品名称: "); scanf("%s", products[*count].name); printf("请输入产品数量: "); scanf("%d", &products[*count].quantity); printf("请输入产品价格: "); scanf("%f", &products[*count].price); (*count)++; printf("产品已成功添加。 "); } void displayProducts(Product *products, int count) { printf("产品列表: "); printf("名称\t数量\t价格 "); for (int i = 0; i < count; i++) { printf("%s\t%d\t%.2f ", products[i].name, products[i].quantity, products[i].price); } } void sellProduct(Product *products, int count) { char productName[50]; int quantityToSell; printf("请输入要销售的产品名称: "); scanf("%s", productName); printf("请输入要销售的数量: "); scanf("%d", &quantityToSell); for (int i = 0; i < count; i++) { if (strcmp(products[i].name, productName) == 0) { if (products[i].quantity >= quantityToSell) { products[i].quantity -= quantityToSell; printf("销售成功! "); } else { printf("库存不足! "); } return; } } printf("未找到该产品! "); } ``` ######[AI写代码神器 | 738点数解答 | 2024-07-10 08:42:19]
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)371
- 工程师必备!10 种工程日常易用管理工具大揭秘(百度文心 | 346点数解答 | 2023-11-09 18:26:09)305
- Golang开发:解析JSON数据时数值默认类型及示例解析(百度文心 | 393点数解答 | 2023-11-09 18:13:06)302
- SQL Working Areas Sizing: Manual vs. Automatic Policy - A Comprehensive Analysis(阿里通义 | 530点数解答 | 2024-05-13 10:55:58)324
- 二手车交易价格预测赛题:思路剖析与程序实现全步骤揭秘(讯飞星火 | 1207点数解答 | 2024-11-17 18:48:26)379
- 揭秘!40 万条数据二手车交易价格预测赛题思路与程序实现全步骤(字节豆包 | 557点数解答 | 2024-11-17 18:50:01)273
- 二手车交易价格预测赛题:从数据处理到模型调优全流程揭秘(阿里通义 | 1736点数解答 | 2024-11-17 18:50:36)298
- 51 单片机:定时器 0 实现 8 个 LED 循环点亮,附代码及优化建议(字节豆包 | 1193点数解答 | 2024-12-27 15:10:29)342
- 用 JS 中 for 循环实现 1 到 100 相加并输出结果到页面的完整代码 ( | 240点数解答 | 2024-05-20 22:11:29)493
- 用 JS 的 while 循环实现 1 到 100 相加并输出到页面的代码揭秘( | 47点数解答 | 2024-05-20 22:16:48)378
- 深度剖析:黑盒、白盒、单元、集成、系统与验收测试的区别与联系 (百度文心 | 424点数解答 | 2023-11-09 18:24:11)314
- Spring Boot 打造 MallShop 购物商城:多角色权限、全业务功能的 Web 应用奇迹 (GPT | 1095点数解答 | 2024-12-09 14:06:47)383