Help c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help c#

Can someone help me with this: https://sololearn.com/coach/681/?ref=app The task is to remove the odd inputs and sum up all the even ones

14th Nov 2021, 11:57 AM
Andrius Savčiukas
3 Answers
+ 5
#try this for(int i=0;i<count;i++) { int price = Convert.ToInt32(Console.ReadLine()); if(price %2==0){ totalAmount+=price; } else{ continue; }
15th Nov 2021, 7:35 AM
Simba
Simba - avatar
0
Simba This is the closest I got int amount = Convert.ToInt32(Console.ReadLine()); int count = 0; int totalAmount = 0; while (count<amount) { count++; int price = Convert.ToInt32(Console.ReadLine()); //skip the odd numbers for(int i=0;i<count;i++) { if(i%2==0){ totalAmount+=price; } else{ continue; } } } Console.WriteLine(totalAmount);
14th Nov 2021, 12:37 PM
Andrius Savčiukas
0
SoloProg doesn’t work. For example, if you input: 3 40 50 55 The output is supposed to be 90, because it takes out 55 and adds 40 and 50 together and etc.
14th Nov 2021, 3:33 PM
Andrius Savčiukas