← Back to Menus & Validation
Question 467
Lamp Brightness Menu
Lamp Brightness Menu
A lamp has a brightness from 0 to 3, starting at 0. Show the menu 1) Brighter, 2) Dimmer, 3) Show, 4) Quit and read the choice with the prompt Choice: , stripped. Choice 1 adds one and prints Brightness: <n>, unless it is already 3, in which case print Already at maximum. and change nothing; choice 2 subtracts one and prints the same line, unless it is already 0, in which case print Already off.; choice 3 prints Brightness: <n>; choice 4 prints Goodbye! and leaves the loop; anything else prints Unknown choice - try again.. Input: one choice per line, ending with 4. The prompt is part of the output, so each message follows Choice: .
Expected Output:
1) Brighter 2) Dimmer 3) Show 4) Quit Choice: Already off. 1) Brighter 2) Dimmer 3) Show 4) Quit Choice: Brightness: 1 1) Brighter 2) Dimmer 3) Show 4) Quit Choice: Brightness: 2 1) Brighter 2) Dimmer 3) Show 4) Quit Choice: Brightness: 3 1) Brighter 2) Dimmer 3) Show 4) Quit Choice: Already at maximum. 1) Brighter 2) Dimmer 3) Show 4) Quit Choice: Brightness: 3 1) Brighter 2) Dimmer 3) Show 4) Quit Choice: Goodbye!
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Menus & Validation
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.