#include<stdio.h>
#include<string.h>
#define N 5
struct books
{
int bno;
char bname[20]; //书名
char field[20]; //类型
char author[20]; //作者
char publisher[30]; //出版社
float price; //价格
};
int main()
{
struct books book[N];
int i, j, k;
char isc = 'n', isb = 'n';
int bno, count[N] = { 0 };
float total = 0, pp;
printf("输入书号 书名 类型 作者 出版社 价格\n");
for (i = 0; i < N; i++)
{
printf("NO.%d:", i + 1);
scanf("%d %s %s %s %s %f", &book[i].bno, book[i].bname, book[i].field, book[i].author, book[i].publisher, &pp);
book[i].price = pp;
}
printf("\n-------------\n");
printf("图书订单");
do
{
printf("输入书号和数量");
scanf("%d %d", &bno, &k);
isb = 'n';
for (j = 0; j < N; j++)
{
if (bno == book[j].bno)
{
count[j] += k;
isb = 'y';
}
}
if (isb == 'n')
printf("继续购买吗?(y/n);");
scanf("%c", &isc);
} while (isc == 'y');
printf("\n-----------------------\n");
printf("购书清单:\n");
printf("书号\t 书名\t 作者\t 单价\t 数量\n");
for (i = 0; i < N; i++)
{
if (count[i] != 0)
{
printf("%d\t%s\t%s\t%.2f\t%d\n", book[i].bno, book[i].bname, book[i].author, book[i].price, count[i]);
total += count[i] * book[i].price;
}
}
printf("\n----------------\n");
printf("\t\t\t总价:%.2f\n", total);
return 0;
}
购书(氵文)
最新推荐文章于 2024-10-28 00:45:37 发布