看板 civil96 關於我們 聯絡資訊
不知道為什麼 一直跑不出來耶 總是有錯誤 又不知道電腦顯示什麼... 什麼叫做沒有給定初始值啊...!? 還有什麼沒有相符的IF... 以下是我的CODE //price.cpp //tell customers how much they should pay. #include <iostream> #include <iomanip> using namespace std; int main () { int price, N; cout<<"Please enter the number of T-shirts."<<endl; cin>>N; if (N<0) cout<<"Error!! Please check the number you enter again."; else if (N>=0 && N<3) price=N*12; else if (N>=3 && N<10) price=N*10; else if (N>=10 && N<=24) price=N*7; cout<<"The price is"<<price<<"dollars"<<endl; else if (N>24) cout<<"sorry,you can only buy less than 24 T-shirts."; return 0; } 好像是倒數第三行有IF的問題吧... 我找不到助教 他也還沒回我信 可是下禮拜要交了... 有人看得出來我錯在哪嗎??!! 在此深深感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.165.219.212
piggyHoward:你第三個else if下的內容 要{}不然只會做第一行 10/25 13:51
coople:我不懂你的意思耶...剛剛把{}到處加了一加結果還是一樣... 10/25 14:34
piggyHoward:不然的話就是else if下的cout要移到最後一個else if 10/25 14:34
piggyHoward:的後面 10/25 14:34
piggyHoward:照你寫的應該是要把第三個else if 下的cout移到後面 10/25 14:37
alicebunny:每一個else if(條件)後面都要cout吧? 10/25 16:38
ceoper256:elseif(10~24) {price=; cout<<;} 超過一個分號要括 10/25 17:14
coople:謝謝各位!!問題已經神奇的解決了!! 10/25 18:16
coople:在此重重感謝各位!!解決了我一個心腹大患XD 10/25 18:17
tinachiu2114:大人,我錯了 請原諒小的吧orz 10/25 21:50
tinachiu2114:一直看不到你的留言我還以為你都做好了= = 10/25 21:51
coople:下次我會注意msn大魔王的陰險詭計!!呵呵 愛你喔ˇˇ 10/26 09:06