| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 889 人关注过本帖
标题:超市收银编程有问题
只看楼主 加入收藏
C语言盲1
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-6-18
收藏
 问题点数:0 回复次数:0 
超市收银编程有问题
中间有些问题没定义好,哪位大神能帮帮忙,万分感谢!!!
#include <stdio.h>
int main()
{   int j;int select;
    struct good goods[N];
    void build(),display(),buy(),money();
    void add(),check();
    printf("***************************\n");
    printf("1.建立商品信息库\n");
    printf("2.输出商品信息\n");
    printf("3.购买商品\n");
    printf("4.结账\n");
    printf("5.查看销售情况\n");
    printf("6.退出\n");
    printf("***************************\n");
    while(1)
    {
        printf("请输入选择序号\n");
    scanf("%d",&select);
    if(select<1||select>6)
    {
        printf("输入有误,请重新输入\n");
    }
    else
    switch(select)
    {
    case 1:build();continue;
    case 2:display();continue;
    case 3:buy();continue;
    case 4:money(j);continue;
    case 5:check();continue;
    case 6:printf("谢谢使用。\n");exit(0);
    }
    }
}
void build()
{
    FILE *fp;
    int i;
    printf("请依次输入商品信息\n");
    for( i=0;i<N;i++)
    {
        printf("商品序号:");
        scanf("%s",goods[i].num);
        printf("商品名:");
        scanf("%s",goods[i].name);
        printf("进价:");
        scanf("%f",&goods[i].in_price);
        printf("售价:");
        scanf("%f",&goods[i].out_price);
        printf("数量:");
        scanf("%d",&goods[i].amount);
    }
    if((fp=fopen("goods","w"))==NULL)
    {
        printf("can't open the file\n");
        return;
    }
    fwrite(goods,sizeof(struct good),N,fp);
    fclose(fp);
    printf("***************************\n");
}
void display()
{
    int i;
    FILE *fp;
    if((fp=fopen("goods","r"))==NULL)
    {
        printf("can't open the file\n");
        return;
    }
    for(i=0;fread(goods+i,sizeof(struct good),1,fp)!=0;i++)
    {
        printf("商品序号 商品名  售价 数量\n");
        printf("%5s\t%7s\t%8.2f\t%d\n",goods[i].num,goods[i].name,goods[i].out_price,goods[i].amount);
        printf("***************************\n");
    }
    fclose(fp);
}
void buy()
{
    int menu();
    void add();
    void revise();
    void show();
    void del();
    while(1)
    {
        switch(menu())
        {
        case 1:add();show();break;
        case 2:revise();break;
        case 3:del();break;
        case 4:
            printf("***************************\n");
            printf("1.建立商品信息库\n");
            printf("2.输出商品信息\n");
            printf("3.购买商品\n");
            printf("4.结账\n");
            printf("5.查看销售情况\n");
            printf("6.退出\n");
            printf("***************************\n");return;
        }
    }
}
int menu ()
{
    int choose;
    printf("***************************\n");
    printf("1.购买商品\n");
    printf("2.修改数量\n");
    printf("3.删除商品\n");
    printf("4.退出\n");
    printf("***************************\n");
    printf("请选择操作序号\n");
    while(scanf("%d",&choose))
    {
        if(choose<1||choose>5)
        {
            printf("输入错误,请重新输入!\n");
            continue;
        }
        else break;
    }
    return choose;
}       void add()
{
    int i,m=0;
    char numb[50];
    char choice;
    do
    {
        printf("请输入要选购商品的序号:\n");
        scanf("%s",numb);
        for(i=0;i<N;i++)
        {
            if(strcmp(goods[i].num,numb)==0)
            {
                strcpy(buy_g[j].num,goods[i].num);
                strcpy(buy_g[j].name,goods[i].name);
                buy_g[j].in_price=goods[i].in_price;
                buy_g[j].out_price =goods[i].out_price;
                printf("商品序号   商品名    售价     剩余数量\n");
    printf("%5s\t%7s\t%8.2f\t%d\n",goods[i].num,goods[i].name,goods[i].out_price,goods[i].amount);break;
            }
        }
        {
            if(strcmp(goods[i].num,numb)==0)
            {
                printf("输入购买数量:");
                scanf("%d",&m);
                while(m>goods[i].amount)
                {
                    printf("输入错误,请重新输入\n");
                    printf("输入购买数量");
                    scanf("%d",&m);
                }
                buy_g[j].amount=m;
                j++;
            }
           else
           printf("无此商品\n");
        }
           printf("是否继续购买?请输入Y或者N\n");
           getchar();
           scanf("%c",&choice);
    }while(choice=='Y');
}
void show()
{
    int i;
    printf("购买的商品\n");
    printf("商品序号   商品名    售价     数量\n");
    for(i=0;i<j;i++)
    {
    printf("%5s\t%7s\t%8.2f\t%d\n",buy_g[i].num,buy_g[i].name,buy_g[i].out_price,buy_g[i].amount);
    }
}
void revise()
{
    char numbe[50];
    int i;
    printf("请输入要修改商品的序号\n");
    scanf("%s",numbe);
    for(i=0;i<j;i++)
    {
        if(strcmp(buy_g[i].num,numbe)==0)  break;
    }
    printf("购买的商品\n");
    printf("商品序号   商品名    售价     数量\n");
    printf("%5s\t%7s\t%8.2f\t%d\n",buy_g[i].num,buy_g[i].name,buy_g[i].out_price,buy_g[i].amount);
    printf("请重新输入数量\n");
    scanf("%d",&buy_g[i].amount);
}
void del()
{
    int i;
    char numb[50];
    printf("请输入要删除的商品序号\n");
    scanf("%s",numb);
    for(i=0;i<j;i++)
    {
        if(strcmp(buy_g[i].num,numb)==0)
        {
            buy_g[i].amount=0;
            break;
        }
    }
    printf("所购买的商品\n");
    for(i=0;i<j;i++)
    {
        if(buy_g[i].amount!=0)
        {
            printf("商品序号   商品名    售价     数量\n");        printf("%5s\t%7s\t%8.2f\t%d\n",buy_g[i].num,buy_g[i].name,buy_g[i].out_price,buy_g[i].amount);
        }
        else continue;
    }
}
void money()
{
    float n=0,total=0,pay;
    int i=0;
    for(i=0;i<j;i++)
    {
        n=buy_g[i].out_price*buy_g[i].amount;
        total += n;
    }
    printf("总费用:%8.3f\n",total);
    do
    {
        printf("实际付款:");
        printf("\n");
        scanf("%f",&pay);
        if(pay<total)
        {
            printf("金额错误,请重新输入!\n");
        }
    }while(pay<total);
    printf("找零:");
    printf("%8.3f\n",pay-total);
    printf("***************************\n");
    printf("1.建立商品信息库\n");
    printf("2.输出商品信息\n");
    printf("3.购买商品\n");
    printf("4.结账\n");
    printf("5.查看销售情况\n");
    printf("6.退出\n");
    printf("***************************\n");
}
{
    int i;
    int m;
    float q,n=0;
    printf("商品销售情况\n");
    printf("商品序号   商品名    售价     剩余数量\n");
    for(i=0;i<N;i++)
    {
        for(m=0;m<j;m++)
        {
            if(strcmp(goods[i].num,buy_g[m].num)==0)
            {
                 printf("%5s\t%7s\t%8.2f\t%d\n",goods[i].num,goods[i].name,goods[i].out_price,goods[i].amount-buy_g[m].amount);
                 break;
            }
        }
    }
    printf("总盈利:\n");
    for(i=0;i<j;i++)
    {
        q=(buy_g[i].out_price-buy_g[i].in_price)*buy_g[i].amount;
        n+=q;
    }
    printf("¥");
    printf("%8.2f\n",n);
    printf("***************************\n");
    printf("1.建立商品信息库\n");
    printf("2.输出商品信息\n");
    printf("3.购买商品\n");
    printf("4.结账\n");
    printf("5.查看销售情况\n");
    printf("6.退出\n");
    printf("***************************\n");
}

搜索更多相关主题的帖子: display include money 信息 
2015-06-18 12:22
快速回复:超市收银编程有问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.093860 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved