Remember
This is a mistake that almost every newcomer will make. That's why I like C # more. This does not allow to “fail”.
What you did wrong is that you failed the switch statement. Try using the value 0 as the value of result . It will go through all cases. When the switch queue completes, the following case is true. Therefore, we need to add a break; statement break; for each case of the switch statement.
switch (result) { case 0: result_amount = 500; break; case 1: result_amount = 600; break; case -1: result_amount = 700; break; }
But sometimes we want to fail. For example, when we want to calculate the number of days per month:
switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 2: days = 28; case 4: case 6:
source share