← Back to Loops
Question 369
Sum Until Zero
Sum Until Zero
Read whole numbers one per line and add them up until a 0 is read; the 0 is a sentinel that ends the loop and is not added. Print the sum in the form Sum: <total>. Input: several lines, each an integer, the last one 0, no prompts. Use a while loop whose condition compares the latest value with 0.
Expected Output:
Sum: 18= newline. The output ends with a newline — print one after the last line.
Hints2 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.