Re: [問題] 海龍公式
寫個加法函式的例子給你看好了
#include<iostream>
using namespace std;
int add(int a, int b)
{
int result;
result=a+b;
return result;
}
int main()
{
int x,y,answer;
cout<<"x=";
cin>>x;
cout<<"y=";
cin>>y;
answer=add(x,y);
cout<<"x+y="<<answer<<"\n";
return 0;
}
這樣應該就知道要怎麼改了吧?
※ 引述《diana76 (白鳳丸)》之銘言:
: 剛學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: 140.112.213.158
→
09/20 12:08, , 1F
09/20 12:08, 1F
→
09/20 12:10, , 2F
09/20 12:10, 2F
→
09/20 12:14, , 3F
09/20 12:14, 3F
→
09/20 12:14, , 4F
09/20 12:14, 4F
推
09/20 12:17, , 5F
09/20 12:17, 5F
推
09/20 16:53, , 6F
09/20 16:53, 6F
→
09/20 17:30, , 7F
09/20 17:30, 7F
推
09/20 18:09, , 8F
09/20 18:09, 8F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章