当前位置: 代码迷 >> C语言 >> scanf : floating point formats not linked,什么意思?
  详细解决方案

scanf : floating point formats not linked,什么意思?

热度:1293   发布时间:2007-09-28 15:04:08.0
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  

----------------解决方案--------------------------------------------------------
scanf ("%g",&grades);
它是int 的.
----------------解决方案--------------------------------------------------------
回复:(nuciewth) scanf (

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


----------------解决方案--------------------------------------------------------
  相关解决方案