Oct 22, 2010 at 12:17am UTC
and i run the program i have no results only have my first cout not the second one.... anybody... please show me my mistake....
int main()
{
double x,myexpx,myexp1,myexp2,expx,fact,i;
fact=1;
ofstream output("e:result12.dat");
cout<<" .........."<<endl;
output<<" ......... "<<endl;
x=5.7;
myexp1=1;
myexp2=x;
i=2;
expx=myexp1+myexp2;
while (fabs(myexpx-myexp1 >= 10e-9))
{
fact=fact*1;
myexp1=expx;
expx=expx+pow(x,i)/fact;
i=i+1;
cout<< "..... " <<"i= "<<i<<expx<<endl;
output<< ".... " <<"i= "<<i<<expx<<endl;
}
system("PAUSE");
return 0;
}
Oct 22, 2010 at 2:07am UTC
myexpx is uninitialized .
Recommendations for next time:
1. use code tags
2. step through the code in your mind or learn to step through code with a debugger
Oct 22, 2010 at 4:53am UTC
And give your variables meaningful names.
Oct 22, 2010 at 10:40am UTC
well i correct the mistake on the while loop it was expx not(myexpx).... but i still get the wrong result any suggestion??and i am sorry about the code tags ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
int main()
{
double x,myexp1,myexp2,expx,fact,i;
fact=1;
ofstream output("e:result12.dat" );
cout<<" ....." <<endl;
output<<" ..... " <<endl;
x=5.7;
myexp1=1;
myexp2=x;
i=2;
expx=myexp1+myexp2;
while (fabs(expx-myexp1 >= 10e-9))
{
fact=fact*1;
myexp1=expx;
expx=expx+pow(x,i)/fact;
i=i+1;
cout<< "..... " <<"i= " <<expx<<endl;
output<< ".... " <<"i= " <<expx<<endl;
}
system("PAUSE" );
return 0;
}
Last edited on Oct 22, 2010 at 10:40am UTC