The problem is this: I set a variable in the method, then I create an array in which, depending on the value of the counter, the formulas for calculating these variables change, after all if, the cycle should postpone the sum of the obtained values and write to the array. but it gives an error. that the variables were not described (not calculated). Please tell me how to remove the error. I give the approximate code below. Ps is required if to replace with switch. But the error there also remains.
public static void Ar() { double A,B,C,At,q=50; if (q <30) { A = 0; } else { A=... // какая-то опред. формула. эт неважно } for (int i = 0; i < 2; ++i) { if (i == 0) { A = ... // какая-то опред. формула. эт неважно B = ... // какая-то опред. формула. эт неважно C = ... // какая-то опред. формула. эт неважно } if (i == 1) { A= ... // какая-то опред. формула. эт неважно B = ... // какая-то опред. формула. эт неважно C =... // какая-то опред. формула. эт неважно } Array[i] = A+B+C; } }
Array
not defined anywhere, what should it be according to your idea? - GrundyA, B, C
In the place of their declaration, explicitly initialize them, for example,double A = 0, B = 0, C = 0;
instead ofdouble A, B, C;
(so that the compiler was sure that these variables will be necessarily initialized by the time they are added here:Array[i] = A+B+C;
) - StateItPrimitive