I have a little problem: I have all the odd numbers that need to be added to this code, but I don't know why it won't contain all the odd negative values. I'm still pretty new to coding, so I'd appreciate it if you could keep it simple. Thanks.
int total2 = 0;
int[] A = new int[12] {2,3,-5,-67,23,-4,243,-23,2,-45,56,-9};
for (int i = 0; i < A.Length; i++)
{
if (A[i] % 2 == 1)
{
total2 += A[i];
}
Console.WriteLine("index: {0} value: {1} total: {2}",
i, A[i], total2);
}
Console.ReadKey();
source
share