You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.4 KiB
89 lines
2.4 KiB
#include<stdio.h>
|
|
#include<string.h>
|
|
int main()
|
|
{
|
|
printf("\t\t\t\t* * * <书店存货清单> * * *\t\t\t\n");
|
|
printf("\n");
|
|
char name[100],c,b[3]={0,0,0};
|
|
int i,n=0,j,k;
|
|
struct qd
|
|
{
|
|
char name[100]; //书名
|
|
char author[100]; //作者
|
|
char cbs[100]; //出版社
|
|
long cbrq; //出版日期
|
|
double price; //单价
|
|
int wz; //图书位置(编号)
|
|
int sl; //数量(存货)
|
|
};
|
|
|
|
struct qd a[3]= //图书目录
|
|
{
|
|
{"C程序设计","谭浩强","清华大学出版社",20100604,33.00,1,99},
|
|
{"高等数学","同济大学数学系","高等教育出版社",20070606,29.40,2,99},
|
|
{"Java开发手册","杨冠宝","电子工业出版社",20180101,28.40,3,99},
|
|
};
|
|
|
|
loop: printf("【请输入书名】\n"); //程序开始
|
|
fflush(stdin); //清空输出
|
|
gets(name);
|
|
j=0;
|
|
for(i=0;i<3;i++)
|
|
{
|
|
j++;
|
|
if(strcmp(a[i].name,name)==0) //判断用户所选书籍
|
|
{
|
|
printf("书名:");
|
|
puts(a[i].name);
|
|
printf("作者:");
|
|
puts(a[i].author);
|
|
printf("出版社:");
|
|
puts(a[i].cbs);
|
|
printf("出版日期:%d\n",a[i].cbrq);
|
|
printf("价格:%lf\n",a[i].price);
|
|
printf("位置:%d\n",a[i].wz);
|
|
printf("库存:%d\n",(a[i].sl-b[i]));
|
|
|
|
k=a[i].sl-b[i]; //更新库存
|
|
|
|
printf("【请输入数量】\n");
|
|
fflush(stdin);
|
|
scanf("%d",&n);
|
|
|
|
b[i]=b[i]+n; //更新库存
|
|
|
|
if(n<=k)
|
|
printf("总价格为:%f\n\n",(n*a[i].price));
|
|
else
|
|
printf("【所需数量不在库存范围内】\n");
|
|
|
|
printf("【是否还想买其他书籍】?\n");
|
|
printf("【是】 则输入 Y或y\n【否】 则单击 回车\n");
|
|
fflush(stdin);
|
|
scanf("%c",&c);
|
|
if(c=='y'||c=='Y')
|
|
goto loop; //返回开始,多次购买
|
|
else
|
|
{
|
|
j=0;
|
|
printf("*****谢谢,再见!*****\n");
|
|
}
|
|
}
|
|
}
|
|
if(j==3) //多次未找到目标书籍
|
|
{
|
|
i=0;
|
|
printf("【未找到该书籍,是否还想买其他书籍?】\n");
|
|
printf("【是】 则输入 Y或y\n【否】 则单击 回车");
|
|
fflush(stdin);
|
|
scanf("%c",&c);
|
|
if(c=='y'||c=='Y')
|
|
goto loop; //返回开始
|
|
else
|
|
{
|
|
printf("*****谢谢,再见!*****\n");
|
|
}
|
|
}
|
|
return 0; //程序结束
|
|
}
|