Re: [考題] 100年地特四等程式語言

看板Examination (國家考試)作者 (MJIB)時間13年前 (2013/04/01 14:52), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《elone (吃大便打線 ...)》之銘言: 謝謝您的熱心 但我發現version 1還是編譯錯誤 結果如下所述 原因應該就是我編譯器太老舊啦(Turbo C 1987, 1988) ^^ 我只是單純找個免安裝編譯器 主要讓我練習打打程式 : 剛回到家 幫你 重新調整一下 : // version 1 如果 salary 用的是 int 那麼你 * 0.05 就不會有小數 : #include <cstdlib> : #include <cstdio> : int main() : { : int salary; : printf("Please input your salary:"); : scanf("%d",&salary); : if(salary>=40000) : { : salary *= 0.05; : printf("Your tax is %d.",salary); : } : else : { : printf("Your tax is 0."); : } : return 0; : } =>Unable to open include file "CSTDLIB" =>Unable to open include file "CSTDIO" =>Constant out of range in comparison in function main/*if(salary>=40000)那行*/ 改成<stdio.h>後,結果和原來一樣 : //version 2 : #include <cstdlib> : #include <cstdio> : int main() : { : // 不好意思 我習慣用double @@ : double salary; //如果用float : printf("Please input your salary:"); : scanf("%lf",&salary); //這邊要改成 %f : if( salary >=40000) : { : salary *= 0.05; : printf("Your tax is %f.",salary); : } : else : { : printf("Your tax is 0."); : } : return 0; : } =>改成<stdio.h>,確實可以正常執行,和float & %f結果一樣 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.32.73.12
文章代碼(AID): #1HMIwRlT (Examination)
文章代碼(AID): #1HMIwRlT (Examination)