006-004-008
Do-While Loop: Menu Selection
Medium
Problem Description
Do-while loop: Menu Selection
In this problem, you will create a program that repeatedly reads integer input using a do-while loop, displays "Selected: Option A" for input 1, "Selected: Option B" for input 2, and prints "Goodbye!" when 0 is entered.
Learning Objective: Write repetitive processing that executes at least once using do-while loops
Create a menu selection simulation program. Use a do-while loop so that processing executes first and the exit condition is checked afterward. Continue looping until the user inputs 0, then terminate.
Input
Multiple lines of input (integers)
- 1: Option A
- 2: Option B
- 0: Exit
Output
Display selected option, show goodbye message when 0 is input
Examples
Example 1
Input:
1
2
0
Output:
Selected: Option A
Selected: Option B
Goodbye!
Example 2
Input:
0
Output:
Goodbye!
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up