A good answer might be:
number += (number % 2 == 1 ) ? 1 : 0 ; | |
Many-way Branches
Often a program needs to make a choice among several options based on the value of a single expression. For example, a clothing store might offer a discount that depends on the quality of the goods:
code.
To execute this fragment, look down the list of cases to match the value in code. The statment between the matching case and the next break is executed. All other cases are skipped. If there is no match, the "default" case is chosen. Warning: the complete rules for switch statments are complicated. Read on to get the details. | |
QUESTION 5:If code is 'C', what is the discount? Click Here after you have answered the question |