标题:scanf : floating point formats not linked,什么意思?
只看楼主
bluesky3810
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-9-17
 问题点数:0 回复次数:2 
scanf : floating point formats not linked,什么意思?
今天自己尝试着做一个成绩统计计算的小程序,结果运行完全出乎意外,请各位给瞧瞧错在哪儿了?
/*program to calculate the average of a set of grades and count the number of failing test grades */
#include <stdio.h>
main ()
{
int grades,sum=0,grade_counter;
float average;
char end_flag;
printf ("please enter the scores one by one!\n");
for (grade_counter=1;grade_counter<101;++grade_counter)
{
printf ("score %i: ",grade_counter);
scanf ("%g",&grades);
if (grades<0 || grades>100)
printf ("sorry,what you've just entered exceed the right range of score,please enter a new score between 0~100!");
else
printf ("you've just entered a non-number,do you want to end entering? (Y/N)");
/*当输入非数字字符时,是否意味着输入完成,可以结果了*/
scanf ("%c",&end_flag);
{
if (end_flag=='y')
break;
else
printf ("please continue to enter,make sure what you entered is a number between 0~100");
}
printf ("%i\n",grades);
sum=sum+grades;
}
average=(float) sum/grade_counter;
printf("The average score is: %f",average);
return 0;
}


不明白之处:
1:程序中并没有打印"scanf : floating point formats not linked"的指令,为何运行结果中会打印出这些字符?是什么意思啊?
2:为什么会提示按任意键继续,但按了任意键后运行框会自行关闭


运行结果如下图:

搜索更多相关主题的帖子: point floating formats linked scanf 
2007-09-28 15:04
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
得分:0 
scanf ("%g",&grades);
它是int 的.

倚天照海花无数,流水高山心自知。
2007-09-28 15:12
bluesky3810
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-9-17
得分:0 
回复:(nuciewth) scanf (

谢了,
居然犯下如此低级错误.

2007-09-28 16:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-173653-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.118145 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved