0
我正在嘗試使用函數來計算二階方程的輸出,但Dev C++一直給我輸出「[Error] 1退出狀態「。 我是C++的新手,如果我犯了一些愚蠢的錯誤,請提前抱歉。「[錯誤] ld返回1退出狀態」功能
#include <iostream>
#include <cmath>
using namespace std;
float equation1 (float, float, float);
float equation2 (float, float, float);
main()
{
float a, b, c, Res1, Res2;
cout << "Insert the parameters of the equation.\n";
cin >> a >> b >> c;
if (a == 0)
{
Res1 = b/c;
cout << "It's a 1st degree eq. and the result is " << Res1 << endl;
}
else
{
Res1 = equation1 (a, b, c);
Res2 = equation2 (a, b, c);
cout << "The results of the eq. are " << Res1 << " and " << Res2 << endl;
}
system ("pause");
return 0;
}
float equation1 (double a, double b, double c)
{
float D, Res1;
D = (b * b) - 4 * a * c;
Res1 = (- b + sqrt(D))/(2 * a);
return Res1;
}
float equation2 (double a, double b, double c)
{
float D, Res2;
D = (b * b) - 4 * a * c;
Res2 = (- b - sqrt(D))/(2 * a);
return Res2;
}
歡迎來到Stack Overflow。請花些時間閱讀[The Tour](http://stackoverflow.com/tour),並參閱[幫助中心](http://stackoverflow.com/help/asking)中的資料,瞭解您可以在這裏問。 –
我想你可能是想寫'int main(){...}'。其次,連接器未能找到'equation1(float,float,float)'的定義,同樣''equation2(float,float,float)'。請注意,定義的函數「float equation1(double,double,double)'會重載您的第一個聲明。 – WhiZTiM
@WhiZTiM我應該怎麼做才能避免過載? – Sam