[請問] 一題C語言

看板C_and_CPP作者 (......)時間14年前 (2011/03/20 21:35), 編輯推噓0(007)
留言7則, 4人參與, 最新討論串1/1
※ [本文轉錄自 ask 看板 #1DXW64u3 ] 作者: supercygnus (......) 看板: ask 標題: [請問] 一題C語言 時間: Sun Mar 20 21:30:41 2011 #include <stdio.h> #include <stdlib.h> int main (void){ float x; float s=0.0f; printf("請輸入工作時數"); scanf("%f",&x); printf("%.1f",x); if(x<=60){ s+=x*75; printf("薪資為:%.3f\n",s); } else if(60<x<=75){ s+=60*75+(x-60)*75*1.25; printf("薪資為:%.3f\n",s); } else if(x>75){ s+=60*75+15*75*1.25+(x-75)*75*1.75; printf("薪資為:%.3f\n",s); } system("pause"); return 0; } 我工作時數用80輸入,跑出的結果是6375.000 但是正確新資是6562.5 為什麼我跑不出正確結果= = -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.167.108.56 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.167.108.56

03/20 21:41, , 1F
別把浮點數和整數混用
03/20 21:41, 1F

03/20 21:42, , 2F
我沒混用啊..兩個都是浮點數
03/20 21:42, 2F

03/20 21:46, , 3F
你的乘法的部份....
03/20 21:46, 3F

03/20 21:46, , 4F
(60<x<=75) 在C裡 這樣寫 不是你要的語意
03/20 21:46, 4F

03/20 21:49, , 5F
喔 原來如此,謝
03/20 21:49, 5F

03/21 16:59, , 6F
(60<x<=75)等同於((60<x) <= 75) 一定為真
03/21 16:59, 6F

03/21 16:59, , 7F
(60<x) 的結果不是1就是0,一定小於等於75
03/21 16:59, 7F
文章代碼(AID): #1DXWAjyX (C_and_CPP)