1

I did all good in check50 .. except this one thing in greedy

:( input of 4.2 yields output of 18
   \ expected output, but not "22\n"

This is my code

1
  • please don't post your entire program publicly.
    – curiouskiwi
    Commented Jul 14, 2014 at 23:40

1 Answer 1

5

You should use the round() function to round your float to the nearest int! Casting a float to an int truncates all the digits after the decimal point. Also, 4.2 isn't necessarily stored as 4.2 because floats are not precise.

6
  • Thank you very much! :) Commented Jul 15, 2014 at 0:30
  • sir i'm facing the same problem, but your answer is not working for me. Can you please tell me why?
    – user7679
    Commented Jul 14, 2015 at 19:40
  • hi, @JitenderSinghVirk! why don't you start up your own post?
    – kzidane
    Commented Jul 14, 2015 at 19:46
  • but there is already a same question as mine.
    – user7679
    Commented Jul 14, 2015 at 19:49
  • @JitenderSinghVirk if it's the same question and you applied the same answer and it doesn't work, then probably you have something else in the pocket!
    – kzidane
    Commented Jul 14, 2015 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .