switch problem

this is part of the codes for my matrix problem.
when i run the codes, only Inverse matrix is working, but the button for Upper Triangular, and determinant are not working. i think it's because i make them in switch, and there is flag for each cases. but i don't know how to write the right codes to display the results based on the flags.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134`` ``````void CA5::OnInverse() { flag=1; Compute(); } void CA5::OnUpperTri() { flag=2; Compute(); } void CA5::OnDeterminant() { flag=3; Compute(); } void CA5::Compute() { GetInput(); CString s; double B[N+1][N+1], X[N+1][N+1], g[N+1][N+1]; double Sum,m,q,p,product; switch(flag) { case 1: { GetInput(); CString s; //identity matrix for (i=1; i<=N; i++) for (j=1; j<=N; j++) { if (i==j) B[i][j]=1; else B[i][j]=0; } // row operations for (k=1;k<=N-1;k++) for (i=k+1;i<=N;i++) { m=a[i][k]/a[k][k]; for (j=1;j<=N;j++) { a[i][j] -= m*a[k][j]; B[i][j] -= m*B[k][j]; } } // backward substitutions for (i=N;i>=1;i--) for (j=1;j<=N;j++) { Sum=0; for (k=i+1;k<=N;k++) Sum += a[i][k]*X[k][j]; X[i][j]=(B[i][j]-Sum)/a[i][i]; } } break; case 2: { //uppertringular //row operations for (k=1; k<=N-1; i++) for (i=k+1; i<=N; i++) { q=a[i][k]/a[k][k]; for(j=1;j<=N;j++) g[i][j] -=q*a[k][j]; } } break; case 3: { //determinant //row operations for (k=1; k<=N-1; k++) for (i=k+1; i<=N; i++) { p=a[i][k]/a[k][k]; for (j=1; j<=2; j++) a[i][j]-=p*a[k][j]; } product=1; for (i=1; i<=N; i++) product *=a[i][i]; } break; } //displayresult for all 3 cases // case 1 for (i=1;i<=N;i++) { for (j=1;j<=N;j++) { s.Format(L"%lf",X[i][j]); sa1[i][j].SetWindowText(s); } } // case 2 for (i=1;i<=N;i++) { for (j=1;j<=N;j++) { s.Format(L"%lf",g[i][j]); sa2[i][j].SetWindowText(s); } } //case 3 s.Format(L"%lf",product); sa3.SetWindowText(s); }``````
Topic archived. No new replies allowed.