Chapter 6-2 : the sum trick

 the sum trick 

This trick is similar to the counter trick, and involves accumulating a value with each turn of the repeat loop.

However, in the case of the sum, it's not a question of counting the number of turns of the loop, but of adding up the numbers read from the keyboard, so as to know, at the end of the reading, the total sum of the numbers that have been read.

To do this, all you have to do is add the new number read to the total number already read in a variable.

As with the counter, it's essential to set to zero the content of the variable used to sum up the numbers read before reading them in a loop.

The general program will look like this:

1. Set 0 in the sum variable
2. REPEAT
3.      Request the number from the computer user
4.      Read the number and place it in the number variable
5.      Take the contents of the sum variable, add the contents of the number variable and
            put the resulting total into the sum variable,
which deletes the old contents of sum
6. UNTIL the end of number reading from keyboard
7. Display "The total of numbers read from the keyboard is equal to", sum

It's up to you to adapt this general program to the case of the bank clerk robot.

Good work.