I don’t understand what is going on with this switch statement. I’m trying to have the user input l for less and m for more. If they put less then it would do the calculations under the ‘l’ case only. But this seems to be asking the user for input from the ‘l’ case AND going to the ‘m’ case and asking again so the user has to input l l for less and m m for more instead of just once.
Is this a problem with trying to use switch or a problem with the way I wrote the code?
while (choice == console.next().charAt(0));
EDIT: Figured out this was asking for input instead so it kept asking twice each time.
You’re asking for choice twice, once in the case statements:
and again in the while condition, i.e.,
Solution: Get the input only once.