[問題] 海龍公式

看板C_and_CPP (C/C++)作者 (白鳳丸)時間16年前 (2009/09/18 18:49), 編輯推噓6(609)
留言15則, 11人參與, 最新討論串1/2 (看更多)
剛學C++ 學長出了一個作業_海龍公式 本人寫完後發現有點問題 回傳值的問題 但是不知道要怎麼解決通常不是可以在 int main()的()中寫上函數嗎? 有點不太懂這部份 不知道這種問題在這邊可不可以問? 如果不行問的話會自D #include<iostream> #include<cmath> using namespace std; double a,b,c,s,area; int math() { cout<<"Please input the three values for the lengths of the sides of a triangle."<<endl<<"a="; cin>>a; cout<<"b="; cin>>b; cout<<"c="; cin>>c; s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c)); } int main(int math) { if(a+b>c&&a+c>b&&b+c>a) cout<<"The lengths cannot be those of the sides of a triangle."<<endl; else cout<<"The areaof the triangle is "<<area<<endl; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.57.78.163

09/18 18:51, , 1F
不太懂你在問什麼
09/18 18:51, 1F
就是我寫了一個程式,但是他跑不出來,出現了ERROR 說是回傳值不正確,於是我想說會不會是這邊錯了int main(int math) ※ 編輯: diana76 來自: 61.57.78.163 (09/18 18:56)

09/18 18:58, , 2F
海龍公式..... 好久以前的東西啊~~
09/18 18:58, 2F
恩阿!不知道能不能幫我跑跑看,到底是哪裡出了問題XD ※ 編輯: diana76 來自: 61.57.78.163 (09/18 19:01)

09/18 19:03, , 3F
int main() { math(); ...... }
09/18 19:03, 3F

09/18 19:06, , 4F
看看書吧
09/18 19:06, 4F

09/18 19:34, , 5F
你連最基本的hello world 應該都不能編譯成功吧
09/18 19:34, 5F

09/18 20:55, , 6F
你寫兩個main()要做什麼?
09/18 20:55, 6F

09/18 21:11, , 7F
他沒有寫兩個 main 吧, 一個 main 一個 math XD
09/18 21:11, 7F

09/18 21:13, , 8F
啊呀我眼殘了...@_@
09/18 21:13, 8F

09/18 21:21, , 9F
找一個函式呼叫的範例來看一下吧
09/18 21:21, 9F

09/19 00:33, , 10F
又是一個規劃錯誤的例子,應該用float卻用int
09/19 00:33, 10F

09/19 00:33, , 11F
不過當然應該解決其他更大的問題先
09/19 00:33, 11F

09/19 01:19, , 12F
你不太熟吼!!
09/19 01:19, 12F

09/19 11:40, , 13F
沒仔細看內容,不過原po的int math() 沒回傳值..所以會錯
09/19 11:40, 13F

09/20 00:13, , 14F
因為沒return?
09/20 00:13, 14F

09/20 11:20, , 15F
不只吧 ... 他根本沒有在主函式呼叫math呀
09/20 11:20, 15F
文章代碼(AID): #1AisMeWD (C_and_CPP)
討論串 (同標題文章)
以下文章回應了本文
完整討論串 (本文為第 1 之 2 篇):
6
15
文章代碼(AID): #1AisMeWD (C_and_CPP)