“[错误] ld 返回 1 退出状态”函数
"[Error] ld returned 1 exit status" on function
我正在尝试编写一个程序来使用函数计算二次方程的输出,但 Dev C++ 一直给我输出“[错误] Id 返回 1 退出状态”。
我是 C++ 的新手,如果我犯了一些愚蠢的错误,请提前道歉。
#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;
}
更改函数定义中的类型。您正在使用双精度,然后 C++ 期望使用浮点运算(精度低于双精度)。
float equation1 (float a, float b, float c)
{
float D, Res1;
D = (b * b) - 4 * a * c;
Res1 = (- b + sqrt(D)) / (2 * a);
return Res1;
}
float equation2 (float a, float b, float c)
{
float D, Res2;
D = (b * b) - 4 * a * c;
Res2 = (- b - sqrt(D)) / (2 * a);
return Res2;
}
我正在尝试编写一个程序来使用函数计算二次方程的输出,但 Dev C++ 一直给我输出“[错误] Id 返回 1 退出状态”。 我是 C++ 的新手,如果我犯了一些愚蠢的错误,请提前道歉。
#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;
}
更改函数定义中的类型。您正在使用双精度,然后 C++ 期望使用浮点运算(精度低于双精度)。
float equation1 (float a, float b, float c)
{
float D, Res1;
D = (b * b) - 4 * a * c;
Res1 = (- b + sqrt(D)) / (2 * a);
return Res1;
}
float equation2 (float a, float b, float c)
{
float D, Res2;
D = (b * b) - 4 * a * c;
Res2 = (- b - sqrt(D)) / (2 * a);
return Res2;
}