SCRIPTING-AND-PROGRAMMING-FOUNDATIONS practice question 15 of 25

A program adds a service fee to the total cost of concert tickets when the tickets are printed and mailed to customers. Another service fee is also added if the tickets are delivered overnight. Which control structure should be used?

Full set: 137 questions
Answer options
A: While loop
B: Do-while loop
C: If statement
D: Multiple if statements Correct answer
Correct Answer:
D. Multiple if statements
Explanation

The problem describes two separate, non-exclusive conditions. A fee is added for printed/mailed tickets, and another fee can be added for overnight delivery. A customer could have printed tickets sent via overnight delivery, meaning both conditions are true and both fees should apply. Multiple, independent if statements are required to check each condition separately. This ensures that each applicable fee is added to the total cost without precluding the other.

Why Incorrect

A: A while loop is an iteration structure used to repeat code while a condition is true, not for a one-time decision. B: A do-while loop is also for iteration and is inappropriate for this conditional logic. C: A single if statement (or an if-else structure) can only handle one condition or a set of mutually exclusive conditions.

References

- Gaddis, T. (2021). Starting Out with Programming Logic and Design (5th ed.). Pearson. Chapter 4, "Decision Structures and Boolean Logic," explains that multiple independent if statements are used when a series of non-exclusive decisions must be made.

- Zelle, J. M. (2017). Python Programming: An Introduction to Computer Science (3rd ed.). Franklin, Beedle & Associates. Chapter 7, "Decision Structures," illustrates how separate if statements allow for checking multiple conditions where more than one can be true.

- UC Berkeley, EECS Department. (n.d.). CS 61A: Structure and Interpretation of Computer Programs. Course materials on Control and Environments discuss the use of separate conditional statements for independent checks versus if-elif-else for mutually exclusive choices.

Scroll to Top