帮我用c语言写一个超市管理系统的登录系统,购物车系统
时间: 2023-06-07 11:07:12 浏览: 69
好的,我会根据你的要求编写一个超市管理系统的登录系统和购物车系统。以下是C语言的代码示例:
登录系统:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct user {
char username[20];
char password[20];
};
int main() {
struct user users[3];
strcpy(users[0].username, "user1");
strcpy(users[0].password, "1234");
strcpy(users[1].username, "user2");
strcpy(users[1].password, "5678");
strcpy(users[2].username, "user3");
strcpy(users[2].password, "9012");
char username[20];
char password[20];
int i, flag = 0;
printf("请输入用户名:");
scanf("%s", username);
for(i = 0; i < 3; i++) {
if(strcmp(username, users[i].username) == 0) {
flag = 1;
printf("请输入密码:");
scanf("%s", password);
if(strcmp(password, users[i].password) == 0) {
printf("登录成功!\n");
break;
} else {
printf("密码错误!\n");
break;
}
}
}
if(flag == 0) {
printf("用户名不存在!\n");
}
return 0;
}
购物车系统:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct product {
char name[20];
double price;
};
int main() {
struct product products[3];
strcpy(products[0].name, "苹果");
products[0].price = 3.5;
strcpy(products[1].name, "香蕉");
products[1].price = 2.8;
strcpy(products[2].name, "橙子");
products[2].price = 4.0;
int id, num, i, flag = 0;
double total = 0.0;
printf("请选择要购买的商品编号(1-3):\n");
scanf("%d", &id);
printf("请输入要购买的数量:\n");
scanf("%d", &num);
for(i = 0; i < 3; i++) {
if((i+1)==id) {
flag = 1;
printf("已选择商品:%s,单价为:%.2f元,数量为:%d\n", products[i].name, products[i].price, num);
total = products[i].price * num;
printf("总价为:%.2f元\n", total);
break;
}
}
if(flag == 0) {
printf("输入的商品编号不存在!\n");
}
return 0;
}
希望能帮到你!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)