printf("use cesius,and enter q to quit.\n");scanf("%f",& temperture);為什么輸入 q 就結(jié)束了求解#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貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊
程序運(yùn)行時(shí)現(xiàn)執(zhí)行語(yǔ)句“printf("use cesius,and enter q to quit.\n");”在界面上輸出“use cesius,and enter q to quit”接著執(zhí)行到“scanf("%f",& temperture);”時(shí)程序會(huì)等待鍵盤輸入,當(dāng)你輸入“q”時(shí),temperture得到你輸入的“q”值,但是之后沒有語(yǔ)句了,所以程序就結(jié)束了!

慕運(yùn)維8079593
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
printf("use cesius,and enter q to quit.\n");
scanf("%s",& temperture); //%f是浮點(diǎn)型輸入,字符串輸入應(yīng)該用%s
- 2 回答
- 0 關(guān)注
- 341 瀏覽
添加回答
舉報(bào)
0/150
提交
取消