#2
shaoyuan2008-09-10 23:26
|
紧急求助
//用结构体输入数据,输入1继续输入,2结束,并按照书名排序输出。
#include"stdio.h"
#include"string.h"
//结构体
struct Book{
char name[20];
int price;
int num;
int amout;
}book[20];
int count=3;
//输出
void output(struct Book book[],int sum )
{
int i;
for(i=0;i<sum;i++)
{
printf("书名是:\t");printf("单价是:\t");printf("数量是:\t");printf("该书的总价是:\t");
printf("\n");
printf("%s\t\t",book[i].name);
printf("%d\t\t",book[i].price);
printf("%d\t\t",book[i].num);
printf("%d,%d,%d\t",book[i].amout=book[i].num*book[i].price);
printf("\n");
}
return;
}
//排序
void sort(struct Book book[], int sun)
{
struct Book zemp;
int i;
for(i=0;i<sun;i++)
{
if(strcmp(book[i].name,book[i+1].name)<0)
{
zemp=book[i];
book[i]=book[i+1];
book[i+1]=zemp;
}
}
output(book,count);
return;
}
void main()
{
int i,y;//i 变量
for(i=0;i<count;i++)
{
printf("请输入图书的书名:\n");
scanf("%s",book[i].name);
printf("请输入图书的价格:\n");
scanf("%d",&book[i].price);
printf("请输入图书的数量:\n");
scanf("%d",&book[i].num);
do{
printf("是否继续增加一本书的信息:(1/2)");
scanf("%d",&y);
}while(y==1);
}
printf("***********************************************\n");
printf("排序前\n");
output(book,count);
printf("***********************************************\n");
printf("按书名排序后为:\n");
//printf("按书名排序为:\n");
sort(book,count);
//printf("***********************************************\n");
//printf("按书名排序后为:\n");
//output(book,count);
}
有几个问题我控制不住.
1.count 不应该是具体的值。它是当输入2时,结束并统计count的值。输出
2。排序,好像没什么错啊。可是排不出来
3。就是输入1继续,输入2结束,