亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

您好,一些關于C語言小問題 ,關于quit語句!

您好,一些關于C語言小問題 ,關于quit語句!

C++ C
陪伴而非守候 2021-11-11 11:07:31
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”值,但是之后沒有語句了,所以程序就結束了!

查看完整回答
反對 回復 2021-11-14
?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

printf("use cesius,and enter q to quit.\n");
scanf("%s",& temperture); //%f是浮點型輸入,字符串輸入應該用%s

查看完整回答
反對 回復 2021-11-14
  • 2 回答
  • 0 關注
  • 344 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號