What's the problem of the flowing program?

• 问题

• what's the problem of the flowing program?

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double f(double);
double xpoint(double,double);
double root(double);
int main()
{
double x1,x2,f1,f2,x;
do
{
cout<<"input x1,x2: ";
cin>>x1>>x2;
f1=f(x1);
f2=f(x2);
}
while(f1*f2>=0);
cout<<setiosflags(ios::fixed)<<setprecision(7);

cout<<"A root is: "<<x<<endl;

return 0;
}
double f(double x)
{
double y;
y=x*x*x-5*x*x+16*x-80;
return y;
}
double xpoint(double x1,double x2)
{
double y;
y=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));
return y;
}
double root(double x1,double x2)
{
double y1,y,x;
y1=f(x1);
do
{
x=xpoint(x1,x2);
y=f(x);
if(y*y1>0)
{
y1=y;
x1=x;
}
else
x2=x;
}
while(fabs(y)>=0.00001);
return x;
}

2011年8月2日 17:21

答案

• variable 'x' used without having been initialized and referenced.
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
• 已标记为答案 2011年8月9日 9:57
2011年8月3日 3:31