| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 983 人关注过本帖
标题: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
快速回复:scanf : floating point formats not linked,什么意思?
数据加载中...
 
   



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

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