006-003-008

while Loop: Sum of Input Values

Medium

Problem Description

while loop: Sum of Input Values

In this problem, you will create a program that repeatedly reads integers using a while loop until 0 is entered, accumulates all non-zero values, and displays the final sum to standard output.

Learning Objective: Understand conditional repetitive processing using while loops

Overview

Create a program that receives multiple integers as input and calculates the sum until 0 is entered. The 0 is not included in the sum and is used as a loop termination condition.

Specifications

  • Use a while loop to repeatedly read integers
  • Exit the loop when input is 0
  • Accumulate non-zero input values
  • Output the final sum

Input Format

5
10
3
0

Output Format

Total: 18

Note

5 + 10 + 3 = 18 (0 is not included)

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