好的程序编译,但输出错误。任何帮助都是极好的。我知道关于这个主题有很多其他的例子,我已经看过它们了。似乎没有人帮助我清楚地理解。
#include <iostream>
#include <cmath>
using namespace std;
double quadplus(float a, float b, float c);
double quadminus(float a, float b, float c);
int main()
{
double a, b, c;
double discriminant;
cout << "Please Enter variables for a, b, and c." << endl << endl;
cout << "Enter number for variable a." << endl << endl;
cin >> a;
cout << "Enter number for variable b." << endl << endl;
cin >> b;
cout << "Enter number for variable c." << endl << endl;
cin >> c;
discriminant = (b * b) - (4 * a * c);
if(discriminant == 0)
cout << quadplus(a,b,c) << endl;
else if(discriminant > 0)
cout << quadplus(a,b,c) << endl;
else if(discriminant < 0)
cout << quadminus(a,b,c) << quadplus(a,b,c) << endl;
return 0;
}
double quadplus(float a, float b, float c)
{
return ((-1 * b) + (sqrt(( b * b) - (4 * a * c))) / (2 * a));
}
double quadminus(float a, float b, float c)
{
return ((-1 * b) - (sqrt(( b * b) - (4 * a * c))) / ( 2 * a));
}
答案 0 :(得分:0)
cout << quadplus << endl;
应该是
cout << quadplus(a, b, c) << endl;
此外,如果判别结果是否定的,那么您的解决方案就是
表单x + yi
的复数和您的代码没有正确说明
为了那个原因。如果discriminant != 0
,您应该打印两个根。