关于超市程序的问题,不知道怎么改
程序代码:
/* purpose: 编制一个超市帐务管理程序。假设某超市试营业期间销售10种商品, 商品信息包括商品名称、8位条形码、批发价、零售价、库存等。要求实现如下功能: 编写主菜单。 模拟顾客购物结账过程,输出购物小票,并修改商品信息。 统计当天营业额。 按销量评出最畅销商品。 */ #include"stdio.h" #include"stdlib.h" #include"string.h" #include"conio.h" #define N 10 void printmenu() { int i=0; printf("\n\t欢迎使用YQ超市账务管理系统\n"); for(;i<50;i++) printf("*"); printf("\n1\t输入商品条形码\n"); printf("2\t结账\n"); printf("3\t当天营业额\n"); printf("4\t最畅销商品\n"); printf("5\t退出\n"); for(i=0;i<50;i++) printf("*"); printf("\n"); } struct information{ char name[N];//{"毛巾","牙膏","零食","衣服","饮料","书本","水果","纸巾","杯具","笔"}; char no[N];//{"001","002","003","004","005","006","007","008","009","010"}; int num;//库存 int num2;//售出 double pp;//批发价 double sp;//售价 }goods[N]={"毛巾","000",200,0,1.5,1.9, "牙膏","001",200,0,5.0,5.7, "零食","002",500,0,1.4,2.0, "衣服","003",1000,0,60,79,0, "饮料","004",1000,0,1.2,1.8, "书本","005",1500,0,0.5,1, "水果","006",400,0,1.5,2.0, "纸巾","007",1000,0,1.2,1.8, "杯具","008",200,0,35,40, "笔","009",2000,0,1.0,1.5 }; double sum,sumt=0; void inputcode() { int n,i;char code[N]; printf("请输入商品的条形码和数量,条形码为010时结束全部输入\n"); printf("#############超 市 购 物 小 票##############\n"); printf("代码\t数量\t商品\t价格\n"); sum=0; do { scanf("%s%d",&code,&n); printf("\t"); for(i=0;i<N;i++) if (strcmp(code,goods[i].name)==0) break; goods[i].num-=n; goods[i].num2+=n; sum+=(goods[i].sp)*n; printf("%s\t%lf\t%d\n",goods[i].name,(goods[i].sp)*n); } while(strcmp(code,"010")!=0); sumt+=sum; } void calculate() { float shou; printf("收款:\t"); scanf("%f",&shou); printf("\n找零:\t%lf\n",sum-shou); printf("######\t欢迎下次再来!\t######\n"); } void best() { int i,k; k=0; for (i=1;i<N;i++) if (goods[k].num2<goods[i].num2) k=i; printf("今日最畅销的商品是 代码%s\t名称%s\t单价%lf\t销售量%d\n",goods[k].no,goods[k].name,goods[k].sp,goods[k].num2); } void main() {char ch; int i=0; printmenu(); for (;i==0;){ ch=getch();//scanf("%c",&ch); switch(ch) { case '1':inputcode();break; case '2':calculate();break; case '3':printf("今日营业额为%lf¥\n",sumt);break; case '4':best();break; case '5':i=1;break; default:printf("请重新输入\n");break; } printf("\n"); } }按思路,输入代码和数量,回车,就会打出信息并在内部处理。
我有把inputcode函数里面printf的i不小心打成n的时候 能输出goods【n】的信息 但是改成i 就不行了 全是0
谢谢指教!!!