帮忙看我的一段代码哪里出毛病了

来源:百度知道 编辑:UC知道 时间:2024/05/18 14:41:00
void luru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i>=0;i++) /*无限循环知道用户选择停止*/
{
printf("Please input gukehao:");
gets(data.gukehao);
printf("please input mingzi:");
gets(data.mingzi);
printf("Please input xiaofei:");
gets(temp);data.score[0]=atof(temp); /*不能直接赋值,采用转换函数*/
if(data.score[0]<=5000) /*判断折扣区间*/
n=1;
else
if(data.score[0]<=10000&&data.score[0]>5000)
n=0.95;
else
n=0.9;
fwrite(&data,sizeof(data),1,fp); /*写入文件*/
printf("another?(input n to main/anykey to continue)\n"); /*循环停止判断*/
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);

}

data.score[0]
建议调试或者页面输出这个值,看看这个值是怎么回事。
因为下面这段代码
if(data.score[0]<=5000) /*判断折扣区间*/
n=1;
else
if(data.score[0]<=10000&&data.score[0]>5000)
n=0.95;
else
n=0.9;
由于和data.score[0]相关,可能导致n一直等于1.