← Back to Menus & Validation
Question 455
Count The Menu Visits
Count The Menu Visits
A two-item menu: 1) Ping prints Pong!, 2) Quit prints Pings: <n> (how many times Ping was chosen) and then Goodbye! on the next line before leaving the loop, and anything else prints Unknown choice - try again.. Add the counter: declare it before the loop, add one to it in the Ping branch, and print it in the quit branch. Input: one choice per line, ending with 2. The prompt Choice: is part of the output, so the count follows it on the same line.
Expected Output:
1) Ping 2) Quit Choice: Pong! 1) Ping 2) Quit Choice: Pong! 1) Ping 2) Quit Choice: Pings: 2 Goodbye!
= newline. The output ends with a newline — print one after the last line.
Hints3 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.