Infinite Loop in While Switch(true) CashRegister Free Code Camp

Infinite Loop in While Switch(true) CashRegister Free Code Camp

CodePen CashRegister FCC

be careful, the first comment is turned off to avoid an infinite loop, It was starting at
.009999999999999983
then I multiplied the
changeDue
in the drawer thinking maybe decimal places were throwing off the conditions of the
case switch(true)
then I was hitting the infinite loop at
.50
and after trying to clean up the code a bit, now it occurs at
1
I’m testing the other commented test cases to see if and where they might encounter the same snag

Consider this: When the amount is 1, which of your cases is True?
(And the follow-up: What does this tell you about all of your cases?)

1 Like

Good catch mate

(For the sake of anyone following along that may be confused:)
checking for > meant there was no case in which the value 1 had a true case. The appropriate action is to change all cases to be >= matches (or alternatively, subtract 1 from each of the case-value numbers and retain the >).

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.