0

Here's a screenshot of the math part of the code (copy/paste from/to appliance is not working for me) [link deleted, question is answered] (you can scroll down on image to see check50 results)

0.41*100 = 41, which is 25+10+5+1 = 4 coins.

I don't understand why it says 3 coins instead of 4 on this one but not the others.

1

Just to be clear, your program is telling 3 coins and check50 expects 4 coins. Here is an explanation of what your program is doing for this particular case:

At the start y = 41 and z = 0

Checks condition for enter the while loop y > 0), its true
    First Iteration -> check first condition ( y >= 25 ), its true
        then y = y-25 y = 16 and z++  z = 1
Checks condition to continue the while loop (y > 0), its true
    Second Iteration -> check first condition (y >= 25), its false
                        check second condition (y >= 10 || y < 25), its true
        then y = y - 10 y = 6 and z++ z = 2
Checks condition to continue the while loop (y > 0), its true
    Third Iteration -> check first condition (y >= 25), its false
                        check second condition (y >= 10 || y < 25), its true again, NOTICE THAT 6 < 25 IS TRUE
        then y = y - 10 y = -4 and z++ z = 3

Checks condition to continue the while loop `(y > 0)`, its false because y = -4 at this point

Final result y = -4 and z = 3 then 3 coins

In the other cases your program outputs the correct results just by chance. If you observe the other cases closely, you will see that in any other you need more than one coin smaller than 10 cents like in this one.

Your conditions are not correct you should change all the || (or) operators for the && (and) operators.

By the way, i think you need to install VmWare Tools for Linux Guests to get the copy/paste from/to appliance working, but i am not 100% sure on that.

1
  • that fixed the problem and now it works perfectly, thanks a lot! I thought the || was the same as && but seems I was wrong. – 3231231 Mar 13 '15 at 22:35

You must log in to answer this question.

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