printf("use cesius,and enter q to quit.\n");scanf("%f",& temperture);为什么输入 q 就结束了求解#include <stdio.h>int main(){const int freezing=0;float temperture;int cold_days =0;int all_days = 0;printf("enter the list of daily low temperture.\n");printf("use cesius,and enter q to quit.\n");while(scanf("%f",& temperture)==1){all_days++;if(temperture<freezing)cold_days++;}if(all_days!=0)printf("%d days total: %.f%% were below freezing.\n",all_days,100.0*(float)cold_days/all_days);if(all_days == 0)printf("NO data entered\n");}
2 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
程序运行时现执行语句“printf("use cesius,and enter q to quit.\n");”在界面上输出“use cesius,and enter q to quit”接着执行到“scanf("%f",& temperture);”时程序会等待键盘输入,当你输入“q”时,temperture得到你输入的“q”值,但是之后没有语句了,所以程序就结束了!
慕运维8079593
TA贡献1876条经验 获得超5个赞
printf("use cesius,and enter q to quit.\n");
scanf("%s",& temperture); //%f是浮点型输入,字符串输入应该用%s
- 2 回答
- 0 关注
- 301 浏览
添加回答
举报
0/150
提交
取消