can somebody check the code that i post,for me

abie30 wrote:
>i have bold something on this code
>can u check for me,whether correct or not the code that i write for the dispalay result..
>
>#include "inverse.h"
>
>BEGIN_MESSAGE_MAP(Cinverse,CDialog)
> ON_BN_CLICKED(IDC_COMPUTE, Oninverse)
>END_MESSAGE_MAP()
>
>Cinverse::Cinverse(CWnd* pParentWnd)
>: CDialog (IDD_INVERSEDIALOG, pParentWnd)
>{
> x=new double *[N+1];
> b=new double *[N+1];
> sx=new CString *[N+1];
> sb=new CString *[N+1];
> A=new double *[N+1];
> sA=new CString *[N+1];
> for (int i=0;i<=N;i++)
> {
> A[i]=new double [N+1];
> sA[i]=new CString [N+1];
> b[i]=new double [N+1];
> sb[i]=new CString[N+1];
> }
>
>}
>
>Cinverse::~Cinverse()
>{
> for (int i=0;i<=N;i++)
> delete A[i],sA[i],b[i],sb[i];
> delete x,b,sx,sb,A,sA;
>}
>
>void Cinverse::OnOK()
>{
> CDialog::OnOK();
>}
>
>void Cinverse::DisplayResults()
>{
> for (int i=1;i<=N;i++)
> {
> for (int j=1;j<=N;j++)
> {[b]
> sx[i][j].Format("%lf",x[i][j]);
>
> SetDlgItemText(IDC_x11,((1<=n)?sx[1][1]:""));
> SetDlgItemText(IDC_x12,((1<=n)?sx[1][2]:""));
> SetDlgItemText(IDC_x13,(sx[1][3]):""));
> SetDlgItemText(IDC_x14,(sx[1][4]):""));
> SetDlgItemText(IDC_x15,(sx[1][5]):""));
> SetDlgItemText(IDC_x16,(sx[1][6]):""));
> SetDlgItemText(IDC_x21,(sx[2][1]):""));
> SetDlgItemText(IDC_x22,(sx[2][2]):""));
> SetDlgItemText(IDC_x23,(sx[2][3]):""));
> SetDlgItemText(IDC_x24,(sx[2][4]):""));
> SetDlgItemText(IDC_x25,(sx[2][5]):""));
> SetDlgItemText(IDC_x26,(sx[2][6]):""));
> SetDlgItemText(IDC_x31,(sx[3][1]):""));
> SetDlgItemText(IDC_x32,(sx[3][2]):""));
> SetDlgItemText(IDC_x33,(sx[3][3]):""));
> SetDlgItemText(IDC_x34,(sx[3][4]):""));
> SetDlgItemText(IDC_x35,(sx[3][5]):""));
> SetDlgItemText(IDC_x36,(sx[3][6]):""));
> SetDlgItemText(IDC_x41,(sx[4][1]):""));
> SetDlgItemText(IDC_x42,(sx[4][2]):""));
> SetDlgItemText(IDC_x43,(sx[4][3]):""));
> SetDlgItemText(IDC_x44,(sx[4][4]):""));
> SetDlgItemText(IDC_x45,(sx[4][5]):""));
> SetDlgItemText(IDC_x46,(sx[4][6]):""));
> SetDlgItemText(IDC_x51,(sx[5][1]):""));
> SetDlgItemText(IDC_x52,(sx[5][2]):""));
> SetDlgItemText(IDC_x53,(sx[5][3]):""));
> SetDlgItemText(IDC_x54,(sx[5][4]):""));
> SetDlgItemText(IDC_x55,(sx[5][5]):""));
> SetDlgItemText(IDC_x56,(sx[5][6]):""));
> SetDlgItemText(IDC_x61,(sx[6][1]):""));
> SetDlgItemText(IDC_x62,(sx[6][2]):""));
> SetDlgItemText(IDC_x63,(sx[6][3]):""));
> SetDlgItemText(IDC_x64,(sx[6][4]):""));
> SetDlgItemText(IDC_x65,(sx[6][5]):""));
> SetDlgItemText(IDC_x66,(sx[6][6]):""));
>
> }
> }

>
> SetDlgItemText(IDC_MESSAGE,method+" is successful.");
>}
>
>void Cinverse::DisplayError(CString condition)
>{
> SetDlgItemText(IDC_x11,"");
> SetDlgItemText(IDC_x12,"");
> SetDlgItemText(IDC_x13,"");
> SetDlgItemText(IDC_x14,"");
> SetDlgItemText(IDC_x15,"");
> SetDlgItemText(IDC_x16,"");
> SetDlgItemText(IDC_x21,"");
> SetDlgItemText(IDC_x22,"");
> SetDlgItemText(IDC_x23,"");
> SetDlgItemText(IDC_x24,"");
> SetDlgItemText(IDC_x25,"");
> SetDlgItemText(IDC_x26,"");
> SetDlgItemText(IDC_x31,"");
> SetDlgItemText(IDC_x32,"");
> SetDlgItemText(IDC_x33,"");
> SetDlgItemText(IDC_x34,"");
> SetDlgItemText(IDC_x35,"");
> SetDlgItemText(IDC_x36,"");
> SetDlgItemText(IDC_x41,"");
> SetDlgItemText(IDC_x42,"");
> SetDlgItemText(IDC_x43,"");
> SetDlgItemText(IDC_x44,"");
> SetDlgItemText(IDC_x45,"");
> SetDlgItemText(IDC_x46,"");
> SetDlgItemText(IDC_x51,"");
> SetDlgItemText(IDC_x52,"");
> SetDlgItemText(IDC_x53,"");
> SetDlgItemText(IDC_x54,"");
> SetDlgItemText(IDC_x55,"");
> SetDlgItemText(IDC_x56,"");
> SetDlgItemText(IDC_x61,"");
> SetDlgItemText(IDC_x62,"");
> SetDlgItemText(IDC_x63,"");
> SetDlgItemText(IDC_x64,"");
> SetDlgItemText(IDC_x65,"");
> SetDlgItemText(IDC_x66,"");
> SetDlgItemText(IDC_MESSAGE,
> method+" fails, the matrix is not "+condition+".");
>}
>
>void Cinverse::ReadInput()
>{
> GetDlgItemText(IDC_A11,sA[1][1]);
> GetDlgItemText(IDC_A12,sA[1][2]);
> GetDlgItemText(IDC_A13,sA[1][3]);
> GetDlgItemText(IDC_A14,sA[1][4]);
> GetDlgItemText(IDC_A15,sA[1][5]);
> GetDlgItemText(IDC_A16,sA[1][6]);
> GetDlgItemText(IDC_A21,sA[2][1]);
> GetDlgItemText(IDC_A22,sA[2][2]);
> GetDlgItemText(IDC_A23,sA[2][3]);
> GetDlgItemText(IDC_A24,sA[2][4]);
> GetDlgItemText(IDC_A25,sA[2][5]);
> GetDlgItemText(IDC_A26,sA[2][6]);
> GetDlgItemText(IDC_A31,sA[3][1]);
> GetDlgItemText(IDC_A32,sA[3][2]);
> GetDlgItemText(IDC_A33,sA[3][3]);
> GetDlgItemText(IDC_A34,sA[3][4]);
> GetDlgItemText(IDC_A35,sA[3][5]);
> GetDlgItemText(IDC_A36,sA[3][6]);
> GetDlgItemText(IDC_A41,sA[4][1]);
> GetDlgItemText(IDC_A42,sA[4][2]);
> GetDlgItemText(IDC_A43,sA[4][3]);
> GetDlgItemText(IDC_A44,sA[4][4]);
> GetDlgItemText(IDC_A45,sA[4][5]);
> GetDlgItemText(IDC_A46,sA[4][6]);
> GetDlgItemText(IDC_A51,sA[5][1]);
> GetDlgItemText(IDC_A52,sA[5][2]);
> GetDlgItemText(IDC_A53,sA[5][3]);
> GetDlgItemText(IDC_A54,sA[5][4]);
> GetDlgItemText(IDC_A55,sA[5][5]);
> GetDlgItemText(IDC_A56,sA[5][6]);
> GetDlgItemText(IDC_A61,sA[6][1]);
> GetDlgItemText(IDC_A62,sA[6][2]);
> GetDlgItemText(IDC_A63,sA[6][3]);
> GetDlgItemText(IDC_A64,sA[6][4]);
> GetDlgItemText(IDC_A65,sA[6][5]);
> GetDlgItemText(IDC_A66,sA[6][6]);
> GetDlgItemText(IDC_b11,sb[1][1]);
> GetDlgItemText(IDC_b12,sb[1][2]);
> GetDlgItemText(IDC_b13,sb[1][3]);
> GetDlgItemText(IDC_b14,sb[1][4]);
> GetDlgItemText(IDC_b15,sb[1][5]);
> GetDlgItemText(IDC_b16,sb[1][6]);
> GetDlgItemText(IDC_b21,sb[2][1]);
> GetDlgItemText(IDC_b22,sb[2][2]);
> GetDlgItemText(IDC_b23,sb[2][3]);
> GetDlgItemText(IDC_b24,sb[2][4]);
> GetDlgItemText(IDC_b25,sb[2][5]);
> GetDlgItemText(IDC_b26,sb[2][6]);
> GetDlgItemText(IDC_b31,sb[3][1]);
> GetDlgItemText(IDC_b32,sb[3][2]);
> GetDlgItemText(IDC_b33,sb[3][3]);
> GetDlgItemText(IDC_b34,sb[3][4]);
> GetDlgItemText(IDC_b35,sb[3][5]);
> GetDlgItemText(IDC_b36,sb[3][6]);
> GetDlgItemText(IDC_b41,sb[4][1]);
> GetDlgItemText(IDC_b42,sb[4][2]);
> GetDlgItemText(IDC_b43,sb[4][3]);
> GetDlgItemText(IDC_b44,sb[4][4]);
> GetDlgItemText(IDC_b45,sb[4][5]);
> GetDlgItemText(IDC_b46,sb[4][6]);
> GetDlgItemText(IDC_b51,sb[5][1]);
> GetDlgItemText(IDC_b52,sb[5][2]);
> GetDlgItemText(IDC_b53,sb[5][3]);
> GetDlgItemText(IDC_b54,sb[5][4]);
> GetDlgItemText(IDC_b55,sb[5][5]);
> GetDlgItemText(IDC_b56,sb[5][6]);
> GetDlgItemText(IDC_b66,sb[6][6]);
> for (int i=1;i<=N;i++)
> {
> if (sb[i][i]=="")
> {
> n=i-1; break;
> }
> if (sA[i][i]=="")
> {
> n=i-1; break;
> }
> }
>
> // convert the string input to double
> for (i=1;i<=N;i++)
> {
> for (int j=1;j<=n;j++)
> A[i][j]=atof(sA[i][j]);
> b[i][j]=atof(sb[i][j]);
> }
>
>
>
>}
>
>void Cinverse::Oninverse()
>{
> int i,j,k;
> double Sum;
> bool fStatus=1;
> CString condition="invertible";
> method="Inverse";
> ReadInput();
>
> // perform row operations
> // row operations
> double m;
> 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)/b[i][i];
> }
> if (fStatus)
> DisplayResults();
> else
> DisplayError(condition);
>}
>
>
does it work?
if not, post the errors
if yes, whats the problem?

you could at least say what are you trying to do and what libraries are you using,
and use [code] tags and some proper indentation too, and why the ">" ?
also, use arrays for god's sake (arrays combined with for loops)
Oh I agree, this unfortunately doesn't help anyone help you.

If u need an example of how to ask then check out "For Loop Problem" that i posted yesterday in the beginners forum.

It even has an example of Array and For statments.
Topic archived. No new replies allowed.