← Back to Loops
Question 393
Average Until Zero
Average Until Zero
Read whole numbers one per line until a 0 arrives (the 0 is a sentinel and is not counted), keeping a total and a count with a while loop. After the loop print the average to two decimals in the form Average: <value> using :0.2f; if no numbers came before the 0 print No numbers instead. Input: several lines, each an integer, the last one 0, no prompts.
Expected Output:
Average: 20.00= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Loops
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.