希望C++傳送「長度錯誤」等文字回去

看板Programming作者時間18年前 (2007/09/16 19:01), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/5 (看更多)
請問一下,我在class內偵測傳送過來的資料當東西產生時,傳送錯誤的代碼回去, 如果我希望他傳送的是「長度錯誤」等文字回去,那我該怎麼寫呢? 謝謝! 附上原始語法如下: #include <iostream> class CBox { private: double length; double breadth; double height; public : double Volume(double a,double b,double c) { if (a<0) return -1; else if (b<0) return -2; else if (c<0) return -3; else { length=a; breadth=b; height=c; return height*length*breadth; } } }; using namespace std; int main() { CBox box1; CBox box2; double boxVolume = 0.0; cout << endl << "Volume of box1 =" << box1.Volume(10,50,60); cout << endl << "Volume of box2 =" << box2.Volume(10,-10,20); //雖然資料有錯 但是東西仍產生了 只是這是不良品 cout <<endl; system("PAUSE"); return 0; } -- ┌─────KKCITY─────┐  找歌最方便 KKBOX 歌詞搜尋!! bbs.kkcity.com.tw \^_^ / http://www.kkbox.com.tw └──From:14.19.19.16 ──┘   唱片公司授權,音樂盡情下載 --

09/17 00:20, , 1F
...
09/17 00:20, 1F
文章代碼(AID): #16xGpn00 (Programming)
文章代碼(AID): #16xGpn00 (Programming)