Whats wrong with my program

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;
}
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
And give your variables meaningful names.
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
Topic archived. No new replies allowed.