C++程序求救啊

来源:百度知道 编辑:UC知道 时间:2024/06/01 12:31:47
#include<iostream>
#include<cmath>
using namespace std;
class number
{
public:
number();
void set_number();
float display();
float a,b,c;
};
void number::set_number()
{
cin>>a>>b>>c;
}
float number::display()
{
float e,d;
e=(-b+sqrt(b*b-4*a*c))/(2*a);
d=(-b-sqrt(b*b-4*a*c))/(2*a);
return (e,d);
}
int main(void)
{
number x;
cout<<"please enter the a b c:";
x.set_number();
if (x.a==0)
cerr<<"error"<<endl;
else
if((x.b*x.b-4*x.a*x.c)<0)
cerr<<"error"<<endl;
else
cout<<x.display();
return 0;
}
是不是display函数错了?怎么改?
我在编译到x.display时卡住了

return不能同时返回两个值,但是return可以返回结构体。
你可以创建一个有用两个实数的结构体。
注意这个typedef语句放在using namespace std下面class语句上面。
typedef struct {
float e;
float d;
} obj;
然后将display函数返回类型改称obj
取消display函数中的float e,d语句,添加obj o语句。
修改以下两个赋值语句:
o.e=(-b+sqrt(b*b-4*a*c))/(2*a);
o.d=(-b-sqrt(b*b-4*a*c))/(2*a);
然后返回定义的对象
return o;

return (e,d);
你想用 return 一次返回两个值??那是不可能的....

他妈地,你求还是它求啊