#include #include #include #include #include //书店存货结构体 struct BookStore { char name[100]; //书籍的名称? char author[100]; //?作者? char publish[100]; //出版社 long date; //出版日期 double price; //价格 int location; //在目录中的位置 int count; //当前图书的数量 int exist; //图书是否被借出 }typedef books; struct BookStore a[5]= { {"C语言程序设计","童启","电子工业出版社",2018.2,49.00,1,100}, {"高等数学","同济大学数学系","高等教育出版社",2018.6,47.60,2,100}, {"21天学通C++","刘蕾","""电子工业出版社",2014.1,59.80,3,100}, {"算法基础","Richard E.Neapolitan","人民邮电出版社",2016.3,99.00,4,100}, {"Java从入门到精通","明日科技","清华大学出版社",2016.10,69.60,5,100}, }; void display(); int main() { system("title 书店存货清单"); display(); int i=0,n=0,flag=0,j=0; double sum=0; char c,name[100]; printf("\n\n\n\n\n\n\n\n\n\n\n"); printf(" 欢迎光临本书店,"); flag1: printf("请输入你所需要的书籍名字:"); fflush(stdin); //清空输入缓冲区,为了确保不影响后面的数据读取 gets(name); for(i=0;i<5;i++) { j++; //j加到5说明未找到该书籍 if(strcmp(a[i].name,name)==0) { printf("书名:"); puts(a[i].name); printf(" 作者:"); puts(a[i].author); printf(" 出版社:"); puts(a[i].publish); printf(" 出版日期:%d\n",a[i].date); printf(" 价格:%.2lf\n",a[i].price); printf(" 位置:%d\n",a[i].location); printf(" 库存:%d\n",a[i].count); printf(" 请输入所需数量:"); fflush(stdin); scanf("%d",&n); if(n<=a[i].count){ sum=n*a[i].price; printf(" 总价为:%.2lf\n",sum); } else printf(" 所需数量不在库存范围内\n"); printf(" 是否还想买其他书籍?(Y/N)\n"); fflush(stdin); scanf("%c",&c); if(c=='y'||c=='Y') goto flag1; else if(c=='n'||c=='N') { j=0; //当要退出时使j清0,防止当所找书籍位置为5时跳出for循环而误入下一个if语句 printf(" 谢谢使用,再见!\n"); return 0; } } } if(j==5) { j=0; printf(" 未查找到该书籍,请重新输入\n"); goto flag1; } else { j=0; printf(" 未查找到该书籍,请重新输入\n"); goto flag1; } return 0; } void display() { printf("欢迎使用书店存货清单\n"); printf(" ——计算机1801班罗锐、雷湘辉\n\n"); printf(" (请按任意键继续) "); getch(); system("cls"); system("cls"); }