0
#include<iostream>
using namespace std;


int main()
{
    double x[2] = { 0,0 }, y[2] = { 0,-4 }, z[2] = { -3,0 };
    double CXx, CYx, CZx, CXy, CYy, CZy, CXz, CYz, CZz, D,L;
    L = sqrt(pow(x[1] - x[0], 2) + pow(y[1] - y[0], 2) + pow(z[1] - z[0], 2));
    if (x[0] == x[1] && y[0] == y[1]) {
        if (z[1] > z[0]) {
            double Lambda[3][3] = { { 0,0,1 },{ 0,1,0 },{ -1,0,0 } };
        }
        else {
            double Lambda[3][3] = { { 0,0,-1 },{ 0,1,0 },{ 1,0,0 } };
        }
    }
    else
    {
        CXx = (x[1] - x[0]) / L;
        CYx = (y[1] - y[0]) / L;
        CZx = (z[1] - z[0]) / L;
        D = sqrt(pow(CXx, 2) + pow(CYx, 2));
        CXy = -CYx / D;
        CYy = CXx / D;
        CZy = 0;
        CXz = -(CXx*CZx) / D;
        CYz = -(CYx*CZx) / D;
        CZz = D;
        double Lambda[3][3] = { { CXx,CYx,CZx },{ CXy,CYy,CZy },{ CXz,CYz,CZz } };
    }
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cout << Lambda[i][j] << " ";
        }cout << endl;
    }
    return 0;
}

I am unable to print the 2D array Lambda. It is stated as Undefined. I know that there is some problem with my If-Else statement but I am unable to find what. When I define Lambda before the conditional statements I am getting an output. What do I not understand about the conditional statements.

user6771484
  • 81
  • 2
  • 12
  • 5
    Read your text book's section on variable scope. It'll explain what's wrong faster and probably better than we can. If it can't, [I strongly recommend a better text.](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – user4581301 Aug 04 '17 at 03:50

1 Answers1

0

You define the variable Lambda in the if else statement, so after if else statement, this variable is undefined.

Duong Anh
  • 529
  • 1
  • 4
  • 21