Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of odds = 81 I just cant seem to figure it out in the code.
Console.WriteLine("");
Console.WriteLine("Problem #3 For loop - Add Up the Odds or Evens");
Console.WriteLine("");
Console.WriteLine("Please select 1 for the sum of even numbers or select 2 for sum of odd numbers");
string usrin = Console.ReadLine();
int usrinnum = int.Parse(usrin);
int sumeven = 0;
int sumodd = 0;
int[] Numbers = new int[6] { 25, 26, 27, 28, 29, 30 };
if (usrinnum == 1)
{
foreach (int i in Numbers)
{
if (i % 2 == 0)
sumeven += i;
Console.WriteLine("The sum of the Evens is " + sumeven);
}
}
else
{
foreach (int i in Numbers)
{
if (i % 2 == 1)
sumodd += i;
Console.WriteLine("The Sum of the odds is " + sumodd);
}
}