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 summing, it's not a question of counting the number of turns of the loop, but of adding the numbers read from the keyboard, in order to find out the total sum of the numbers that have been read at the end of the reading.

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 the content of the variable used to sum up the numbers read to zero 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,
this deletes the previous 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

Now it's your turn to adapt this general program to the case of the bank clerk robot.

Good luck!