16. Which control structure should be used?
Answer: B
Multiple if statements should be used.
In this context, multiple if statements are the most appropriate control structure to handle the addition of service fees based on different conditions, such as whether the tickets are printed and mailed or delivered overnight.
A) While loop
A while loop is not suitable for this scenario because it is designed for situations where the number of iterations is not known beforehand and continues until a specified condition is false. Here, the addition of service fees is based on distinct conditions rather than a repeated process.
B) Multiple if statements
Multiple if statements are indeed the correct choice as they allow for separate checks for each condition affecting the total cost of concert tickets. This structure enables the program to add the appropriate service fees based on whether tickets are printed and mailed or delivered overnight without the need for nesting or complex conditions.
C) Do-while loop
A do-while loop is also inappropriate for this situation since it executes at least once and then checks a condition. This structure does not align with the requirement of conditionally applying service fees based strictly on the criteria being met, which is better served by multiple if statements.
D) If statement
While a single if statement could handle one condition at a time, it is insufficient for this scenario as it does not allow for checking multiple independent conditions effectively. Multiple if statements provide the necessary flexibility to evaluate each possible service fee condition separately.
Conclusion
The use of multiple if statements is the definitive solution for this scenario, as it allows for the clear and efficient evaluation of separate conditions regarding service fees. Other options such as while loops and do-while loops do not fit the structure needed for conditional checks, while a single if statement lacks the capability to handle multiple conditions effectively.