006-004-003

Do-While Loop: Menu Selection

Medium

Problem Description

Do-while loop: Menu Selection

Learning Objective: Implement loop that executes at least once using do-while

In this problem, you will create a program that displays a menu using a do-while loop, repeatedly accepts integer input until a valid number (1-3) is entered, and displays the selected result to standard output.

In the loop body of your do-while statement, display the menu and read an integer input. If the input is outside the range 1-3, execute the loop again. Once a valid value is entered, exit the loop and output the selection number.

Input

Multiple lines: Menu selection (integer, 1-3 valid, others cause re-input)

Output

Menu:
1. Start
2. Settings
3. Exit
[wait for input until first valid]
Selected: [selection number]

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