作者diana76 (白鳳丸)
看板C_and_CPP
標題[問題] 海龍公式
時間Fri Sep 18 18:49:11 2009
剛學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
1F:→ james732:不太懂你在問什麼 09/18 18:51
就是我寫了一個程式,但是他跑不出來,出現了ERROR
說是回傳值不正確,於是我想說會不會是這邊錯了int main(int math)
※ 編輯: diana76 來自: 61.57.78.163 (09/18 18:56)
2F:→ jaw109:海龍公式..... 好久以前的東西啊~~ 09/18 18:58
恩阿!不知道能不能幫我跑跑看,到底是哪裡出了問題XD
※ 編輯: diana76 來自: 61.57.78.163 (09/18 19:01)
3F:→ james732:int main() { math(); ...... } 09/18 19:03
4F:推 stonehomelaa:看看書吧 09/18 19:06
5F:推 su35:你連最基本的hello world 應該都不能編譯成功吧 09/18 19:34
6F:→ dendrobium:你寫兩個main()要做什麼? 09/18 20:55
7F:推 ledia:他沒有寫兩個 main 吧, 一個 main 一個 math XD 09/18 21:11
8F:推 dendrobium:啊呀我眼殘了...@_@ 09/18 21:13
9F:→ mantour:找一個函式呼叫的範例來看一下吧 09/18 21:21
10F:→ MOONRAKER:又是一個規劃錯誤的例子,應該用float卻用int 09/19 00:33
11F:→ MOONRAKER:不過當然應該解決其他更大的問題先 09/19 00:33
12F:推 zzsqoo:你不太熟吼!! 09/19 01:19
13F:→ lovecold:沒仔細看內容,不過原po的int math() 沒回傳值..所以會錯 09/19 11:40
14F:推 kiwatami:因為沒return? 09/20 00:13
15F:→ mantour:不只吧 ... 他根本沒有在主函式呼叫math呀 09/20 11:20