Doesn't accept my code ((.. "That's odd ..." | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Doesn't accept my code ((.. "That's odd ..."

8th Jan 2022, 6:30 PM
Alexey
Alexey - avatar
6 Answers
+ 5
Look at the input format. Using the first input, you can get the number of numbers. Then use a for loop to sum whatever comes in from `cin` (if it's even). Basically: ``` int size, number; int sum = 0; cin >> size; for (int i = 0; i < size; i++){ cin >> number; if (number % 2 == 0){ sum += number; } } cout << sum; ```
8th Jan 2022, 6:54 PM
Daniel Tsvetkov
Daniel Tsvetkov - avatar
+ 1
Simplified the code, but the result is the same. 2 tests out of 5 fail. https://code.sololearn.com/cXnjpnBM7lak/?ref=app
8th Jan 2022, 6:42 PM
Alexey
Alexey - avatar
+ 1
Thank you. I haven't read the problem statement) need to be more careful. thanks again!
8th Jan 2022, 6:58 PM
Alexey
Alexey - avatar
0
You want to take a list of numbers and find the sum of all of the even numbers in the list. Ignore any odd numbers. Task: Find the sum of all even integers in a list of numbers. Input Format: The first input denotes the length of the list (N). The next N lines contain the list elements as integers. Output Format: An integer that represents the sum of only the even numbers in the list. Sample Input: 9 1 2 3 4 5 6 7 8 9 Sample Output: 20
8th Jan 2022, 6:31 PM
Alexey
Alexey - avatar
0
I'm trying to solve the problem. The result converges, but the tests fail. Tell me where is the error?
8th Jan 2022, 6:33 PM
Alexey
Alexey - avatar