大神能帮帮看看这C语言题吗?超市会员管理系统
哪里错了程序代码:
// 1111111.cpp : Defines the entry point for the console application. // #include "stdafx.h" /* HELLO.C -- Hello, world */ #include "string.h" #include "stdio.h" #include "conio.h" #include "stdlib.h" #define N 1000 struct huiyuan /*定义会员信息结构体类型*/ { char num[100]; /*卡号*/ char name[20]; /*姓名*/ char ID[30]; /*身份证号*/ char tel[30]; /*电话号码*/ float fen; /*积分*/ char g[10]; /*记录改卡是否已挂失*/ }huiyuan [100]; /*自定义函数*/ void menu(); /*菜单函数*/ void enter(); /*输入函数*/ void search(); /*查找函数*/ void guashi(); /*挂失函数*/ void buy(); /*购书函数*/ void modify(); /*修改函数*/ void output(); /*显示所有数据函数*/ void add(); /*添加信息函数*/ void input(int i); void printf_back(); void printf_out(int i); void printf_face(); float buy_money(float add); float Money(); int modify_data(int i,int n); int save(int n); /*保存数据函数*/ int load(); /*读取数据函数*/ void main() /*主函数*/ { menu(); getch(); } void menu() /*菜单函数*/ { int n,w1; system("cls"); do /*显示菜单*/ { printf("\t\t================================================\n\n"); printf("\t\t================================================\n\n"); printf("\t\t ================= WELCOM!===================\n\n"); printf("\t\t *** 1 .............Enter new information ***\n\n"); printf("\t\t *** 2 .............................buy ***\n\n"); printf("\t\t *** 3 ........................Search or delete or modify ***\n\n"); printf("\t\t *** 4 ............................modify ***\n\n"); printf("\t\t *** 5 ............................guashi ***\n\n"); printf("\t\t *** 6 ............................xian shi ***\n\n"); printf("\t\t *** 7 ..............................add data ***\n\n"); printf("\t\t *** 8 ..............................Exit ***\n\n"); printf("\t\t================================================\n\n"); printf("\t\t================================================\n\n"); printf("\nChoose your number(1-8):[ ]\b\b"); /*选择菜单*/ scanf("%d",&n); if(n<1||n>8) w1=1; else w1=0; } while(w1==1); switch(n) { case 1:enter();break; case 2:buy();break; case 3:search();break; case 4:modify();break; case 5:guashi();break; case 6:output();break; case 7:add();break; case 8:exit(0); } } void enter() /*输入函数*/ { int i,n; printf("How many people do you want to add(0-%d)?:",N-1); scanf("%d",&n); printf("\n Enter data now\n\n"); for(i=0;i<n;i++) { printf("\n Input %dth people record.\n",i+1); input(i); /*调用子函数*/ } if(i!=0){ save(n); } printf_face(); /*显示刚刚输入的所有信息*/ for(i=0;i<n;i++) { printf_out(i);} printf_back(); } void search() /*查找函数*/ { int i,n,k,w1=1,w2,w3,w4,m,a; struct huiyuan p; n=load(); do { printf("\n\nWhich way do you want to choose? \n\t1).By ID 2).By num [ ]\b\b"); scanf("%d",&m); switch(m) { case 1: /*按身份证查找*/ do { k=-1; printf("\n\nEnter danwei that you want to search! ID."); scanf("%s",p.ID); printf_face(); for(i=0;i<n;i++) if(strcmp(p.ID,huiyuan[i].ID)==0) { k=i; printf_out(k);break; /*显示该卡信息*/ } if(k==-1) { printf("\n\nNO exist!please"); /*该卡不存在*/ printf("\n\nAre you again?\n\t1).again 2).NO and back [ ]\b\b"); scanf("%d",&w1); if(w1==2) printf_back(); } } while(k==-1&&w1==1);break; case 2: /*按卡号查找*/ do {k=-1; printf("\n\nEnter num that you want to search! num."); scanf("%s",p.num); printf_face(); for(i=0;i<n;i++) if(strcmp(p.num,huiyuan[i].num)==0) {k=i; printf_out(k);break; /*显示该卡信息*/ } if(k==-1) /*该卡不存在*/ {printf("\n\nNO exist!please"); printf("\n\nAre you again?\n\t1).again 2).NO and back [ ]\b\b"); scanf("%d",&w1); if(w1==2) printf_back(); } } while(k==-1&&w1==1);break; } w4=0;w3=0; if(k!=-1) {printf("\n\nWhat do you want to do?\n\t 1).Search 2).Modify 3).Delete 4).Back menu [ ]\b\b"); scanf("%d",&w2); switch(w2) {case 2:w3=modify_data(k,n);break; case 3:{printf("\nAre you sure?\n\t 1).Sure 2).No and back [ ]\b\b");/*删除函数*/ scanf("%d",&w4); if(w4==1) for(a=k;a<n;a++) {strcpy(huiyuan[a].num,huiyuan[a+1].num); /*删除信息*/ strcpy(huiyuan[a].name,huiyuan[a+1].name); strcpy(huiyuan[a].ID,huiyuan[a+1].ID); strcpy(huiyuan[a].fen,huiyuan[a+1].fen); strcpy(huiyuan[a].g,huiyuan[a+1].g); strcpy(huiyuan[a].tel,huiyuan[a+1].tel); }break;} } if(w4==1) if(w3==1||w4==1) {save(n); printf("\n\nSuccessful.^_^."); printf("\n\nWhant do you want to do? \n\t 1).Search another 2).Back [ ]\b\b" ); scanf("%d",&w2); } } } while(w2==1); menu(); } void modify() /*修改函数*/ {struct huiyuan p; FILE *fp; int i,n,k,w0=1,w1,w2=0; n=load(); do { k=-1; printf_face(); /*显示所有卡信息*/ for(i=0;i<n;i++) {if((i!=0)&&(i%10==0)) {printf("\n\nRemember NO.which needed modify.pass any key to contiune ..."); getch(); puts("\n\n"); } printf_out(i); } do {printf("\n\nEnter NO.that you want to modify! NO.:"); /*选择序号*/ scanf("%s",p.num); for(i=0;i<n;i++) if(strcmp(p.num,huiyuan[i].num)==0) {k=i; p=huiyuan[i]; } if(k==-1)printf("\n\nNO exist!please again"); /*判断是否存在该卡*/ }while(k==-1); printf_face(); printf_out(k); w1=modify_data(k,n); /*调用修改数据子函数*/ if(w1==1) {printf("\nSuccessful ^_^.\n\nAre you modify another ?\n\n\t 1).Yes 2).Back with save\t[ ]\b\b"); scanf("%d",&w0); w2=1; } else {w0=0; if(w2==1) huiyuan[k]=p; } if(w0!=1&&w2==1) save(n); /*保存信息*/ }while(w0==1); menu(); } void guashi() /*挂失函数*/ { int n,i,x; char ID,a,num; n=load(); printf("Enter 1).ID 2).num [ ]\b\b"); scanf("%d",&x); switch(x) {case 1:{printf("\nEnter ID /*用身份证挂失*/ scanf("%s",ID); printf_face(); for(i=0;i<n;i++) /*查找相应信息*/ if(strcmp(huiyuan[i].ID,ID)==0){ printf_out(i); printf("\nAre suer(y/n):[ ]\b\b"); scanf("%s",a); if(strcmp(a,"y")==0) /*判断是否为挂失*/ strcpy(huiyuan[i].g,"diu"); }break;} case 2:{printf("\nEnter num:");/*用卡号挂失*/ scanf("%s",num); printf_face(); for(i=0;i<n;i++) /*查找相应信息*/ if(strcmp(huiyuan[i].num,num)==0){ printf_out(i); printf("\nAre suer(y/n):[ ]\b\b"); scanf("%s",a); if(strcmp(a,"y")==0) /*判断是否为挂失*/ strcpy(huiyuan[i].g,"diu"); } break; }} save(n); printf_back(); } void buy() /*购书函数*/ { float m,n; int x; m=buy_money(n); printf("\nchoose:\t1)go on buying 2)end and back to menu\t [ ]\b\b"); scanf("%d",&x); if(x==1) buy(); else menu(); } float Money() /*处理输入的购书总金额*/ { int i, n,a,b,c; float sum=0.0; float m[100]; printf("\nEnter the number of books:"); /*输入所买书的本书*/ scanf("%d",&n); for(i=0;i<n ;i++){ printf("\nEnter %dth book's money:\n",i+1); /*输入每本书的价格*/ scanf("%f",&m[i]); sum=sum+m[i]; } return sum; } float buy_money(float acc) /*购书打折处理函数*/ { int i,n,a,b,c; char num; /*暂时存储每次购书金额*/ n=load(); acc=Money(); printf("\nEnter card num:"); scanf("%s",num); for(i=0;i<n;i++){ if(strcmp(huiyuan[i].num,num)==0){ a=i; break; } } if(i==n){ /*判断是否为会员*/ printf("\nthis card is no exist!!!"); printf("\nAll books worth %.2f. \n1)buy again. 2)add a card. 3)back to menu. [ ]\b\b",acc); scanf("%d",&c); do{if(c==1)buy(); if(c==2)add(); if(c==3)menu(); }while(c>=1&&c<=3); }else{ printf_face(); /*显示该卡信息*/ printf_out(a); printf("\nAll books worth %.2f ",acc); if(strcmp(huiyuan[a].g,"diu")!=0){ /*判断是否已挂失*/ huiyuan[a].fen=huiyuan[a].fen+acc; if(huiyuan[a].fen>=5000) {acc=acc*0.80; printf("<80%>discount");}/*打折处理*/ else if(huiyuan[a].fen>=2000) {acc=acc*0.90; printf(" <90%>discount");} else if(huiyuan[a].fen>=1000) {acc=acc*0.95; printf(" <95%>discount");} printf("\nShould pay total money:%.2f",acc); save(n); return acc; }else{ printf("\n1)back to menu. 2)search. [ ]\b\b"); scanf("%d",&b); if(b==2)search(); else menu();} }} int modify_data(int i) /*修改数据的子函数*/ {int c,w1; do {puts("\nmodify by=>\n\n 1).num2).name3).ID4).telephone\t[ ]\b\b");/*选择要修改的内容*/ printf("Which you needed?:[ ]\b\b"); scanf("%d",&c); if(c>4||c<1) {puts("\nChoice error!Please again!"); getchar(); } }while(c>4||c<1); do {switch(c) /*修改相应信息*/ { case 1:printf("num:");scanf("%s",huiyuan[i].num);break; case 2:printf("name:");scanf("%s",huiyuan[i].name);break; case 3:printf("ID:");scanf("%s",huiyuan[i].ID);break; case 4:printf("tel:");scanf("%s",huiyuan[i].tel);break; } puts("\nNow:\n"); /*显示刚修改的信息*/ printf_face(); printf_out(i); printf("\nAre you sure?\n\n\t 1).Sure 2).No and remodify 3).Back without save in this time [ ]\b\b"); scanf("%d",&w1); } while(w1==2); return(w1); } void add() /*添加信息函数*/ { int i,n,m,k; FILE*fp; n=load(); printf("How many people are you want to add(0-%d)?:",N-1-n);/*输入要添加的人数*/ scanf("%d",&m); k=m+n; for(i=n;i<k;i++) /*依次输入信息*/ { printf("\nInput %dth people record.\n",i-n+1 ); input(i); } printf_face(); /*显示刚输入的信息*/ for(i=n;i<k;i++){ printf_out(i); } if((fp=fopen("Pro.txt","ab"))==NULL) { printf("cannot open file\n"); } for(i=n;i<k;i++) /*保存数据*/ if(fwrite(&huiyuan[i],sizeof(struct huiyuan),1,fp)!=1) printf("file write error\n"); fclose(fp); printf_back(); } void output() /*显示所有数据函数*/ { int i,n,x; char pa; n=load(); clrscr(); printf("Enter password:\n"); /*输入密码*/ gets(pa); while(strcmp(pa,"12345")!=0){ clrscr(); printf("Enter password again:"); gets(pa); } clrscr(); printf_face(); /*显示所有信息*/ for(i=0;i<n;i++){ printf_out(i); } printf("\n\n1)back to menu. 2)buy. 3)search and delete. 4)modify.\t[ ]\b\b"); scanf("%d",&x); switch(x){ case 1:menu();break; case 2:buy();break; case 3:search();break; case 4:modify();break; default:menu(); }} int save(int n) /*保存数据函数*/ {FILE *fp; int i; if((fp=fopen("Pro.txt","wb"))==NULL) {printf("\nCannot open file\n"); return NULL; } for(i=0;i<n;i++) if(huiyuan[i].num!=0) if(fwrite(&huiyuan[i],sizeof(struct huiyuan),1,fp)!=1) printf("file write error\n"); fclose(fp); } int load() /*读取数据函数*/ {FILE *fp; int i; if((fp=fopen("Pro.txt","rb"))==NULL) {printf("\nCannot open file\n"); return NULL; } for(i=0;!feof(fp);i++) fread(&huiyuan[i],sizeof(struct huiyuan),1,fp); fclose(fp); return(i-1); } void input(int i) /*输入数据的子函数*/ { int k,y; long x; randomize(); x=random(32767); /*随机产生卡号*/ ltoa(x,huiyuan[i].num,10); for(k=0;k<i;k++){ if(strcmp(huiyuan[k].num,huiyuan[i].num)==0) x=random(32767); ltoa(x,huiyuan[i].num,10); } printf("name:"); /*输入姓名*/ scanf("%s", huiyuan[i].name) ; printf("ID:"); scanf("%s",huiyuan[i].ID); /*输入身份证*/ printf("telephone:"); scanf("%s",huiyuan[i].tel); /*输入电话号码*/ huiyuan[i].fen=0.0; /*积分初始值为0.0*/ } void printf_back() /*用于调用其他函数*/ { int j,w; printf("\n\n\tSuccessful!^_^\n\n"); printf("What do you want you to continue to do?\n\n\t1).search or modify\t2).Back to menu.\t3).add data [ ]\b\b"); scanf("%d",&w); if(w==1) search(); if(w==3) add(); if(w!=1&&w!=3) menu(); } void printf_out(int i) /*显示信息函数*/ { if(strcmp(huiyuan[i].g,"diu")==0) printf("%s card yi gua shi!!!\nyou can't use it!!!\n",huiyuan[i].num); else printf("%d%8s%15s%15s%16s%15f\n",i+1,huiyuan[i].num,huiyuan[i].name,huiyuan[i].ID,huiyuan[i].tel,huiyuan[i].fen); } void printf_face() /*显示信息表头*/ { printf("\n xuhao num name ID telephone jifen \n"); }