求高人解释 为什么在 win tc 1.91 下输入时就会自动退出

liukeshao 2011-10-29 11:03:48
为什么在 win tc 1.91 下输入时就会自动退出
#define M 3

struct student{
int num;
float score;
};

main(){
struct student s[M];
int i;
float ave=0;
for(i=0;i<M;i++){
printf("please input the num:");
scanf("%d",&s[i].num);
printf("please input the score:");
scanf("%f",&s[i].score);
ave+=s[i].score/M;
}
for(i=0;i<M;i++){
if(s[i].score>ave){
printf("%6d,%6f\n",s[i].num,&s[i].score);
}
}
getch();
}
...全文
72 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liukeshao 2011-10-29
  • 打赏
  • 举报
回复
用WIN TC 呢
lengxujun 2011-10-29
  • 打赏
  • 举报
回复
用VS跑了一下,没发现什么问题.
liukeshao 2011-10-29
  • 打赏
  • 举报
回复
不行啊
a707000646 2011-10-29
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<conio.h>

#define M 3

struct student{
int num;
float score;
};

main(){
struct student s[M];
int i;
float ave=0;
for(i=0;i<M;i++){
printf("please input the num:");
scanf("%d",&s[i].num);fflush(stdin);
printf("please input the score:");
scanf("%f",&s[i].score);fflush(stdin);
ave+=s[i].score/M;
}
for(i=0;i<M;i++){
if(s[i].score>ave){
printf("%6d,%6f\n",s[i].num,s[i].score);
}
}
getch();
}


添加fflush(stdin)清楚缓冲区的数据
或者使用getchar();来接受回车
liukeshao 2011-10-29
  • 打赏
  • 举报
回复
win TC 不行啊 VC 应该可以
teamos 2011-10-29
  • 打赏
  • 举报
回复
跑了一遍 没任何问题

69,371

社区成员

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

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