+ 2

Please i need to fix this code

using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int[] numbers = new int[5]; int count = 0; int sum = 0; while (count <5) { numbers[count] = int.Parse(Console.ReadLine()); count++; } //your code goes here for(int i = 0;i<numbers.Length;i++;) { if(numbers[i]%2 == 0) { sum += numbers[i]; } } Console.WriteLine(sum); } } }

20th Jan 2023, 10:04 PM
Ka joo
Ka joo - avatar
6 Answers
+ 1
Ka, You've introduced another bug: for(int i=0;i<numbers.Lenght;i++) Now in your 'numbers.Length', you've got your 'th' backwards - 'Lenght'
21st Jan 2023, 11:51 AM
DavX
DavX - avatar
+ 3
You have an extra ; in your loop. for(int i = 0;i<numbers.Length;i++;) Should be: for(int i = 0;i<numbers.Length;i++) Notice the last section, i++, you do not add a semicolon. The error gave the line number.
21st Jan 2023, 12:52 AM
DavX
DavX - avatar
+ 1
Thank you very much it worked And im not a native speaker of English and my English level isnt so good
21st Jan 2023, 7:02 PM
Ka joo
Ka joo - avatar
+ 1
You’re good 👍 english is my primary language and I still make typos.
21st Jan 2023, 7:04 PM
DavX
DavX - avatar
0
Thank You So Much
21st Jan 2023, 7:13 AM
Ka joo
Ka joo - avatar
0
It looks like this now and its not working still using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int[] numbers = new int[5]; int count = 0; int sum = 0; while (count <5) { numbers[count] = Convert.ToInt32(Console.ReadLine()); count++; } //your code goes here for(int i=0;i<numbers.Lenght;i++) { if(numbers[i]%2==0) { sum+= numbers[i]; } } Console.WriteLine(sum); } } }
21st Jan 2023, 7:32 AM
Ka joo
Ka joo - avatar