Can someone please help me in creating an array, I've got a DataTable with 270months columns so I've used a forloop for that. My array has to be the same as C158_Calc but only for 73months. At the moment the array is returnig each element as 0. C158_Calc values are correct.

double[] values = new double[73];
for (int i = 1; i <= 240; i++)
        {
            double BW154_Calc = 0.0;
            if (i == 72)
                BW154_Calc = (C152_Calc * 12 / G169_In) * 100;
            if (i == 240)
                BW154_Calc = (C152_Calc * 12 / G170_In) * 100;

            num3 += BW154_Calc;

                // calculate 6 year IRR
            if (i == 1)
                C158_Calc = H30_Out + C152_Calc;
            if (i >= 2 && i <= 72)
                C158_Calc = C152_Calc;
            if (i == 73)
                C158_Calc = C152_Calc + num3;

                // total 6 year IRR
            for (int j = 1; j == values.Length - 1; j++)
            {
                values[j] = C158_Calc;
            }

                // calculate 20 year IRR
            double C160_Calc = 0.0;
            if (i == 1)
                C160_Calc = H30_Out + C152_Calc;
            else
                C160_Calc = C152_Calc;

You have a small error in for-loop (line 21). For-loop "loops" as long as the condition "j == values.Length - 1" is true. In the first round you have condition 1 == 72 which is always false that's why you never execute the statement in the loop.
Change the condition:

for (int j = 1; j <= values.Length; j++)

and your code works.

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.