Adding Calculator Write a program that simulates an adding machine. Input to the program will be integers, submitted one per line. Input should be handled as follows: a nonzero value should be added into a subtotal; a zero value should cause the subtotal to be printed and reset to zero; two consecutive zeroes should cause the total (not subtotal) of all the values input to be printed and the program to be terminated. Here’s an example of how the program should work. However, it is only an example. Your program should work for any test case. Input is in red and output is in blue. Your program does not need to display colors, they are show here for illustration only so that you can distinguish input and output.

Respuesta :

The calculator program is an illustration of iteration (loop) and conditional statements

What are iterations?

Iterations are program statements that are used to perform repetition operations

What are conditional statements?

Conditional statements are statements used to make decisions

The main programs

The program written in Python, where comments are used to explain each action is as follows:

#This initializes the subtotal and total to 0

subTotal = 0; total = 0

#This initializes the previous number to an empty list

prevNum = []

#This iteration is repeated for valid inputs

while True:

   #This gets the input from the user

   num = int(input())

   #This calculates the subtotal

   subTotal+=num

   #This calculates the total

   total+=num

   #If the current input is 0

   if num == 0:

       #This prints the sub total

       print("Subtotal:",subTotal)

       #This sets the sub total to 0

       subTotal = 0

   #If the previous number is empty

   if len(prevNum) == 0:

       #This sets it to the current input

       prevNum.append(num)

   #If otherwise

   else:

       #If the previous number and the current input are 0

       if(prevNum[0] == 0 and num == 0):

           #This prints the total input

           print("Total:",total)

           #This exits the loop

           break

       #If otherwise

       else:

           #This sets the previous number to the current input

           prevNum[0] = num

Read more about similar programs at:

https://brainly.com/question/26497128