[問題] 一直算出0

看板C_and_CPP作者 (小的)時間14年前 (2009/10/25 18:42), 編輯推噓4(4019)
留言23則, 8人參與, 最新討論串1/1
剛剛寫了一個算電話費率的程式 還沒寫完 想說先測試一種情況 但是他一直算出0= = 能請高手們幫我看一下問題出在哪嗎?? 感激 #include <iostream> using namespace std; double hour,min,min_1,cost; const double RATE=0.40; char day_1,day_2,M,m; int main() { cout<<"This program is to calculate the cost of your call."<<endl; cout<<"Here are the rules of the cost:"<<endl; cout<<"Any call started between 8:00am and 6:00pm,Mon to Fri,is cost 0.4$per min."<<endl; cout<<"Any call started before 8:00am and after 6:00pm,Mon to Fri,is cost 0.25$"<<endl <<"per min."<<endl; cout<<"Any call started on Sat and Sun,is cost 0.15$per min."<<"\n\n\n\n"; cout<<"Enter the first and second letter of the day(like Monday=Mo): "; cin>>day_1>>day_2; cout<<"Enter the time the call started(in 24-hour notation)."<<endl; cout<<"hour: "; cin>>hour; cout<<"min: "; cin>>min; cout<<"Enter the length of the call in min: "; cin>>min_1; while((day_1==M)||(day_1==m)) { if((8<=hour+(min+min_1)/60.0)&&(hour+(min+min_1)/60.0<=18)) cost=min_1*RATE; } cout<<"The cost is: "<<cost; return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.63.2

10/25 18:51, , 1F
=? 應該是==?
10/25 18:51, 1F

10/25 18:56, , 2F
對吼 我改成==還是0= =
10/25 18:56, 2F
※ 編輯: ManInBlackXD 來自: 140.113.63.2 (10/25 19:00)

10/25 19:03, , 3F
M=? m=?
10/25 19:03, 3F

10/25 19:08, , 4F
M跟m就是代表第1個字元 星期一的意思
10/25 19:08, 4F

10/25 19:09, , 5F
用 debugger 來 trace 一下吧
10/25 19:09, 5F

10/25 19:10, , 6F
樓上那是啥 抱歉我新手
10/25 19:10, 6F

10/25 19:26, , 7F
誰能幫幫我= =
10/25 19:26, 7F

10/25 19:29, , 8F
你的開發環境?? 簡單的說就是要你用開發工具的功能, 一
10/25 19:29, 8F

10/25 19:30, , 9F
行一行執行程式碼, 搭配觀察有用到的各個變數來找問題:)
10/25 19:30, 9F

10/25 20:45, , 10F

10/25 23:13, , 11F
推一下樓上的連結, j大您還真有心寫這種介紹:)
10/25 23:13, 11F

10/25 23:13, , 12F
話說~~不得不承認, 小弟我看不習慣中文版的VC啊Q_Q~
10/25 23:13, 12F

10/25 23:13, , 13F
因為我覺得 debugger 真的很重要 但不知為何總被忽略
10/25 23:13, 13F

10/25 23:15, , 14F
小弟以前的入門書好像也沒教基本debug skill與IDE的工具
10/25 23:15, 14F

10/25 23:16, , 15F
雖然說這種東西和語言本身無關, 不同環境/IDE操作方法也
10/25 23:16, 15F

10/25 23:16, , 16F
不一樣; 但總覺得入門書應該寫個一章或附碌來教的~_~
10/25 23:16, 16F

10/25 23:45, , 17F
你的M和m在還沒有賦值前就被拿來比較了
10/25 23:45, 17F

10/25 23:46, , 18F
或是其實你是想寫「 day_1=='M' 」?
10/25 23:46, 18F

10/25 23:48, , 19F
還有你的while一但進入就不會出來了
10/25 23:48, 19F

10/25 23:48, , 20F
10/25 23:48, 20F

10/26 00:18, , 21F
可是就目前看來沒有進去的一天
10/26 00:18, 21F

10/26 00:57, , 22F
為啥不會出來了
10/26 00:57, 22F

10/26 02:10, , 23F
阿你裡面又沒有改變day_1當然是永遠不會出來
10/26 02:10, 23F
文章代碼(AID): #1Av2kXV_ (C_and_CPP)