Why showing wrong answer?

This is my code. https://ide.codingblocks.com/s/68661
I have thought of some possible test cases and it worked perfectly. What is wrong in the code or what testcase wont pass through it?

HI ANKUSH, you have to find sum of odd and even digit values seperately. But you have clubed both these sums in your code. Try the question and again and this time take 2 variables. 1 to hold sum of odd digits and the other to hold sum of even digits and then proceed further as asked by question.

Hope this helps :slight_smile:

Okay. I’ll try this out.

i changed the code as follows
https://ide.codingblocks.com/s/68856
but it still showed wrong answer.

No Ankush, you have did the same thing here and just created 2 extra variables with new names. You have to change your statements in Line 17 and 18. Wright now you are just suming up all the digits of given number irrespective of wether it is odd or even. But you do not have to do this. You have to sum digits which are even separately and odd ones separately. For ex if you are given a no.:

982452

then maintain 2 variables evesum=0, oddsum = 0 ;
and they will be:

                    9   +   8   +   2   +   4   +   5   +   2
evesum =              8    +   2    +  4        +       2 = 16
oddsum =    9                   +                    5        = 14

Now process them further according to questions demand. You just need to change line no. 17.
Hope you understand now :slight_smile: .

Thanks for the explanation. My answer is correct now. Seems like i didnt read the problem properly. :slight_smile:

i was also stucked at the same question,understood the question after reading it 5 th time,little bit tricky(english).

yeah ! i was surprised… the question seemed so easy!

Hey Ankush,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.