New course! Every coder should learn Generative AI!
Try a free lesson0
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
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;
}
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);
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.