Answer:
The code solution is written in Python.
- positiveSum = 0
- negativeSum = 0
- num = int(input("Enter a number: "))
- while(num != 0):
- if(num > 0):
- positiveSum += num
- else:
- negativeSum += num
- num = int(input("Enter a number: "))
- print("Sum of positive number: " + str(positiveSum))
- print("Sum of negative number: " + str(negativeSum))
Step-by-step explanation:
Firstly, we need to create two variables, positiveSum & negativeSum, to hold the running total of the positive and negative input numbers. (Line 1 - 2)
Next, use Python in-built method input() to prompt user for the first input number and assign it to variable num. (Line 4)
Create a while-loop by setting the condition as while input number is not equal to 0, the program shall positive to add the current input number to either variable positiveSum or negativeSum. (Line 6 -10) If the input number is bigger than zero, the current input number should be added to variable positiveSum else it should add to variable negativeSum.
Next, the program shall proceed to prompt user for the next input number. (Line 12)
The entire process is repeated until user enters zero to exit the while loop.
Lastly, display the total of positive and negative numbers. (Line 14 - 15)