C语言超市计价收款系统

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

C语言超市计价收款系统

不吃肉的胖子   2022-05-28 我要评论

学习一个月的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"); 
        }
                
    }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们