软件编程
位置:首页>> 软件编程>> C语言>> C语言实现超市计价收款系统

C语言实现超市计价收款系统

作者:不吃肉的胖子  发布时间:2021-08-21 17:56:47 

标签:C语言,收款系统

本文实例为大家分享了C语言实现超市计价收款系统的具体代码,供大家参考,具体内容如下

学习一个月的C语言,写了一个简易的超市计价收款系统

C语言实现超市计价收款系统

源码如下

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 10
typedef struct ? ?//定义商品的结构体?
{ ??
? ? ?
?? ?char name[10];
?? ?int num;
?? ?float ?price;?
?? ?int ID;?
}Store;
Store store[M];

void shuru( ) ? //定义输入商品的函数?
{
?? ?int i;
?? ?int isgo;
?? ?int n;
?? ?for(i=0;i<M;i++)
?? ?{
?? ??? ?store[i].ID=i+1;//自定义商品的ID?
?? ??? ?printf("输入商品的名字\n");
?? ??? ?scanf("%s",&store[i].name);?
?? ??? ?printf("输入商品的价格\n");
?? ??? ?scanf("%f",&store[i].price);?
?? ??? ?printf("还需要输入商品吗?\n");
?? ??? ?printf("1.YES,2.NO\n");
?? ??? ?scanf("%d",&isgo);
?? ??? ?if(isgo!=2)//判断是否继续输入商品?
?? ??? ?{
?? ??? ??? ?
?? ??? ?}else//不输入商品直接跳出,展示所有商品的信息?
?? ??? ?{
?? ??? ??? ?for(n=0;n<=i;n++)
?? ??? ? ? ?{
?? ??? ? ? ? ? ?printf("商品ID\t商品名字\t商品价格\n");
?? ??? ? ? ? ? ?printf("%d\t,%s\t,%f\n",store[n].ID,store[n].name,store[n].price);
?? ??? ? ? ?}
?? ??? ? ? ?i=10;
?? ??? ?}
?? ??? ?
?? ?}
}

void shopp() ?//购物函数?
{
?? ?int isgo=1;
?? ?int i;
?? ?int n;
?? ?int number;
?? ?int shoppid;?
?? ?float pricenum;
?? ?float pricesum=0.0;
?? ?float priceguke;
?? ??
?? ?
?? ?printf("库存的商品如下\n");
?? ?for(n=0;n<M;n++)
? ? {
? ??? ? ? printf("商品ID\t商品名字\t商品价格\n");
?? ? ? printf("%d\t,%s\t,%f\n",store[n].ID,store[n].name,store[n].price);
?? ? ? if(store[n].price==0)//这里是为了不把没定义的商品不显示出来?
?? ? ? {
? ??? ??? ?n=M;
? ??? ? ? }
?? ?
?? ? ??
? ? }
?? ?while(isgo)//购物?
?? ?{
?? ??? ?printf("按下你需要的商品ID和数量\n");
?? ??? ?scanf("%d,%d",&shoppid,&number);
?? ??? ?pricenum=(store[shoppid-1].price)*number;
?? ??? ?pricesum=pricesum+pricenum;
?? ??? ?printf("你购买的商品%s是%d个,价格是%f,总金额是%f\n",store[shoppid-1].name,number,pricenum,pricesum);
?? ??? ?printf("是否继续购物\n");
?? ??? ?printf("0.退出,1.继续\n");
?? ??? ?scanf("%d",&isgo);?
?? ?}
?? ?printf("输入顾客支付的金钱\n");//结算?
?? ?scanf("%f",&priceguke);
?? ?if(priceguke>=pricesum)
?? ?{
?? ??? ?printf("收到顾客%f元,找回顾客%f元\n",priceguke,priceguke-pricesum);
?? ?}else
?? ??? ?{
?? ??? ?printf("收到的钱小于总金额\n");
?? ?}
?? ?printf("谢谢光临\n");
?? ??? ?
}

main()
{
?? ?int xitong=1;
?? ?

?? ?while(xitong!=3)
?? ?{
?? ??? ?printf("-------------------欢迎登录好浪费超市系统-----------------------\n");
? ??? ? ? ?printf("1.输入商品信息\n");
?? ? ? ?printf("2.购买商品\n");
? ? ? ? printf("3.退出系购买商品统\n");
?? ? ? ?scanf("%d",&xitong);
?? ? ? ?switch(xitong)
?? ? ? ?{
? ? ?? ??? ?case 1:shuru();
? ? ?? ??? ?break;
? ? ?? ??? ?case 2:shopp();
? ? ?? ??? ?break;
? ? ?? ??? ?case 3:printf("欢迎再次使用好浪费超市系统\n");?
? ? ?? ?}
?? ??? ??? ??? ?
?? ?}
}

来源:https://blog.csdn.net/qq_43547520/article/details/118652441

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com