182k views
1 vote
Design the logic for a program that allows a usher to continuously enter numbers until the usher enters 0. Display the sum of the numbers entered.

2 Answers

5 votes

Final answer:

To design the program, initiate a sum at 0, loop to input numbers, adding them to the sum until 0 is entered, then display the sum.

Step-by-step explanation:

Designing a Number Summation Program;

The task includes creating a program logic that allows an usher to consecutively enter numbers. The program will have a loop that continues to prompt for numbers until the usher enters 0, at which point the loop will terminate. As each number is entered, it should be added to a running sum. After exiting the loop, the program will display the sum of all the entered numbers to the usher.

Sample Pseudocode:

sum = 0
while True:
number = input('Enter a number or 0 to stop: ')
if number == 0:
break
sum += number
print('The sum of the numbers is: ', sum)

This pseudocode demonstrates the fundamental logic required to execute the task.

User Taseer
by
5.3k points
3 votes

int sum = 0, n;

do {cin>>n; sum+=n;}while (n!=0);

cout<<sum;

User Hillmark
by
4.5k points