您好,一些关于C语言小问题 ,关于quit语句!

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");

}

陪伴而非守候
浏览 302回答 2
2回答

守候你守候我

程序运行时现执行语句“printf("use cesius,and enter q to quit.\n");”在界面上输出“use cesius,and enter q to quit”接着执行到“scanf("%f",& temperture);”时程序会等待键盘输入,当你输入“q”时,temperture得到你输入的“q”值,但是之后没有语句了,所以程序就结束了!

慕运维8079593

printf("use cesius,and enter q to quit.\n");scanf("%s",& temperture); //%f是浮点型输入,字符串输入应该用%s
打开App,查看更多内容
随时随地看视频慕课网APP