萌新求助

anhe1234 2017-12-23 09:52:47
这是一个管理系统的一部分,链表标红输不出结果,最上面是一些声明和读入文件的函数,最下面是主函数,求原因
#include <stdio.h>
#include <string.h>
float balance[10000];//银行卡余额
int mark[10000];//标记数组
struct Fruit//五种水果
{
char fname[20];
} fruit[5];

struct Info//小票信息
{
int id;//序号
int ftype;//水果种类
float price;//单价
float fnum;// 数量
float total;//总价
float pay;//付款
float ret;//找零
int cardid;//卡号
float befpay;//购物前余额
float aftpay;//购物后余额
int hour;//小时
int minute; //分钟
struct Info *next;
} info[30];

void read()//读入内存
{
FILE *fp;
if((fp=fopen("data.txt","r"))==NULL)
{
printf("数据不存在\n");
return ;
}
int i,j;
char fname[20];
for(i=0; i<30; i++) //把data文件读入内存
{
fscanf(fp,"%d%s%f%f%f%f%f%d%f%f%d%d",
&info[i].id,
fname,
&info[i].fnum,
&info[i].total,
&info[i].pay,
&info[i].ret,
&info[i].cardid,
&info[i].befpay,
&info[i].aftpay,
&info[i].hour,
&info[i].minute
);

for (j=0; j<5; j++) //录入水果代表的数字
if(!strcmp(fname,fruit[j].fname))//如果两个相等,执行下面语句
{
info[i].ftype=j;
break;
}
mark[info[i].id]=1;
}
if((fp=fopen("vip.txt","r"))==NULL)
{
printf("会员信息不存在\n");
return ;
}
int num;
fscanf(fp,"%d",&num);
int u,v;
for (i=0; i<num; i++)
{
fscanf(fp,"%d%d",&u,&v);
balance[u]=v;
}
fclose(fp);
}



void query_big_info()
{
float x,y;
puts("输入价格范围x和y(中间用空格隔开)");
scanf("%lf%lf",&x,&y);
int i;
struct Info *head=NULL,*tmp=NULL;
for (i=0; i<30; i++)
{
if(info[i].total>=x&&info[i].total<=y)
{
if(!tmp)
{
tmp=&info[i];
head=tmp;
}
else
{
tmp->next=&info[i];
tmp=tmp->next;
}
}
}
printf("序号 种类 单价 数量 总价 支付 找零 卡号 购前 购后\n");
while(head)
{
printf("%4.4d %s %.2f %.2f %.2f %.2f %.2f %d %.2f %.2f",
info[i].id,
fruit[info[i].ftype].fname,
info[i].price,
info[i].fnum,
info[i].total,
info[i].pay,
info[i].ret,
info[i].cardid,
info[i].befpay,
info[i].aftpay);
printf("时间: %d:%d\n",info[i].hour,info[i].minute);
}
}

int main()
{
int op;
int i;
for (i=0; i<10000; i++)
mark[i]=0;//标记id是否出现
strcpy(fruit[0].fname,"苹果");
strcpy(fruit[1].fname,"香蕉");
strcpy(fruit[2].fname,"西瓜");
strcpy(fruit[3].fname,"桃子");
strcpy(fruit[4].fname,"橘子");
printf("************************************************************************************************************************\n");
printf("************************************************************************************************************************\n");
printf("\n\n\t\t 欢迎来到水果超市管理系统!(* ^_^ *)\n\n");
printf("************************************************************************************************************************\n");
printf("\n\t\t 请输入操作:\n\t\t1、添加记录\n\t\t2、修改\n\t\t3、删除\n\t\t4、查询\n\t\t5、统计\n\t\t6、会员\n\t\t7、大额购物\n\t\t8、时间段购物信息\n\n");
scanf("%d",&op);
while(op>8||op<1)
{
printf("错误,请输入数字1到8");
printf("\n\t\t 请输入操作:\n\t\t1、添加记录\n\t\t2、修改\n\t\t3、删除\n\t\t4、查询\n\t\t5、统计\n\t\t6、会员\n\t\t7、额购物\n\t\t8、时间段购物信息\n\n");
scanf("%d",&op);
}
read();
if(op==1)
add();
else if(op==2)
update();
else if(op==3)
del();
else if(op==4)
query_fruit();
else if(op==5)
show();
else if(op==6)
query_vip();
else if(op==7)
query_big_info();
else if(op==8)
query_time();
save();
return 0;
}
...全文
185 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
anhe1234 2018-09-02
  • 打赏
  • 举报
回复
感谢大佬,这个是去年的问题现在才看,就是你说的那样
自信男孩 2017-12-25
  • 打赏
  • 举报
回复
void query_big_info()
{
    float x,y;
    puts("输入价格范围x和y(中间用空格隔开)");
    scanf("%f%f",&x,&y);
    int i;
    struct Info *head=NULL,*tmp=NULL;
    for (i=0; i<30; i++)
    {
        if(info[i].total>=x&&info[i].total<=y)
        {
            if(!tmp)
            {
                tmp=&info[i];
                head=tmp;
            }
            else
            {
                tmp->next=&info[i];
                tmp=tmp->next;
            }
        }
    }
    tmp->next = NULL;

    tmp = head;
    printf("序号   种类    单价   数量    总价    支付    找零    卡号    购前    购后\n");
    while(tmp)
    {
        printf("%4.4d  %s   %.2f   %.2f   %.2f  %.2f  %.2f   %d  %.2f  %.2f",
                tmp->id, fruit[tmp->ftype].fname, tmp->price, info->fnum,
                tmp->total, tmp->pay, tmp->ret, tmp->cardid, tmp->befpay,
                tmp->aftpay);
        printf("时间: %d:%d\n", tmp->hour, tmp->minute);
        /*
        printf("%4.4d  %s   %.2f   %.2f   %.2f  %.2f  %.2f   %d  %.2f  %.2f",
               info[i].id,
               fruit[info[i].ftype].fname,
               info[i].price,
               info[i].fnum,
               info[i].total,
               info[i].pay,
               info[i].ret,
               info[i].cardid,
               info[i].befpay,
               info[i].aftpay);
        printf("时间: %d:%d\n",info[i].hour,info[i].minute);
        */
        tmp = tmp->next;
    }
}
参考一下吧; 另外,自己数一下%d,%f个数和后面的参数是否是一一对应的,包括参数类型。
fscanf(fp,"%d%s%f%f%f%f%d%f%f%d%d",
               &info[i].id,
               fname,
               &info[i].fnum,
               &info[i].total,
               &info[i].pay,
               &info[i].ret,
               &info[i].cardid,
               &info[i].befpay,
               &info[i].aftpay,
               &info[i].hour,
               &info[i].minute
              );
scanf("%f%f",&x,&y);
float类型应该以%f接收吧,double采用%lf
萌想1.0详细信息 编辑点评: “有想法,一起来!”真正能帮你实现各种想法的社交聊天交友软件。在萌想你可以发布自己各种想法、许下心愿或发一个求助、互粉畅聊……让我们彼此分享好玩的想法,找到有趣的朋友,一起来把“萌想”变成现实! 【功能特色】 1、发布萌想:“萌想”就是各种有趣好玩的想法,可以是年轻的梦想、恶搞的主意、可爱的冲动、情不自禁的想象或者你的困惑等等,发布出来,找到有同样想法的 “有想法,一起来!”真正能帮你实现各种想法的社交聊天交友软件。在萌想你可以发布自己各种想法、许下心愿或发一个求助、互粉畅聊……让我们彼此分享好玩的想法,找到有趣的朋友,一起来把“萌想”变成现实! 【功能特色】 1、发布萌想:“萌想”就是各种有趣好玩的想法,可以是年轻的梦想、恶搞的主意、可爱的冲动、情不自禁的想象或者你的困惑等等,发布出来,找到有同样想法的人,一起来实现它吧! 2、许下心愿:随时随地许下心愿,萌想帮你制作一张长长的愿望清单,一定会有人帮你实现它! 3、查看附近:精确定位,查看附近萌友的心愿,互相帮助,世界更美好; 4、萌友互粉:互相关注,查看萌友动态,留言、点赞,互动嗨翻; 5、萌友互助:遇到难题?迷惑不解?找萌友支招,就一招; 6、萌友畅聊:志趣相投,在线免费畅聊,激情四射的年代,总有人愿意陪你去冒险。

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧