The problem is here:
while(input != 0)
{
if(input > two_euro)
{
input = input - two_euro;
If your input is at 2, then the while
loop will keep going round, but the if
well never be entered. You specifically check if the input is greater than 2, so you never completely reduce the input to 0.
Let's walk through an example:
input is 4
while (input != 0) => true, enter the loop
if (input > 2) => true, enter the reduction step
input = input-2 => input is 2
while (input != 0) => true, continue the loop
if (input > 2) => false, skip the reduction step
while (input != 0) => true, continue the loop
if (input > 2) => false, skip the reduction step
... continue forever
Supposing you fix the above problem by changing >
to >=
. What will happen if your input is not an even number? Not a whole number? Maybe your while
condition shouldn't check for exactly 0
, but instead check if the input is greater than 0
?
You would need to change your reduction step to always take place while the input is greater than 0 as well, or you would get stuck in an infinite loop with your input at 1 (or any value between 0 and 2).