value of an array is not copied to other array

Hi All,

I'm trying to copy one element value in an array to other array(Line no: 19) in the following program.

There is some problem due to which it is displaying ZERO.

Could someone help me in fixing the Problem in this function member.

Thanks in advance.


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 tdms (int m, float* x,float* y,float* z, float* w, float* u,float tt,float ddt )
{
for(int k=1; k<=2;k++)
     {
          cout<<"\nTime step: "<<ddt*k<<"\n\n";
          h[0]=0;g[0]=0;
          for(int i=1;i<m;i++)           
                {
                       h[i]=z[i]/(y[i]-(x[i]*h[i-1]));
                       g[i]=(w[i]-(x[i]*g[i-1]))/(y[i]-(x[i]*h[i-1]));   
                }             
           un[m-1]=g[m-1];                 
           for(int i=(m-2);i>0;i--)
                 {
                        u[i] =(-h[i]*un[i+1])+g[i];         
                 }
           cout<<m-1<<"\t"<<un[m-1]<<"\n";
           std::copy(u,u+m,un);
           u[m-1]=un[m-1];
           cout<<u[m-1]<<"\n";
           for (int i=1; i<m; i++)
                 { 
                        cout<<i<<"\t"<<u[i]<<"\t"<<un[i]<<"\n";
                 }                     
      }cout<<"\n";
}



Regards,
Vigii
Last edited on
Zero for which element(s) of which array(s)?

Have you tried stepping through it with a debugger to see what;s going on?

Your loops look odd to me. You're starting your loop counters at 1 rather than 0, and your array indices are an inconsistent mix of i and i-1.
No way this will run, so what is g and what is h ?? I guess these are global, but ... however, maybe it's not copying, that doesn't work ??

I checked it (with other values, i think) and all arrays that should contain copies do so at last ... so you'll have to check your calculations, i guess.

Topic archived. No new replies allowed.