Sums with variables

You can make the computer do sums with numbers stored in variables. Try the program below. It makes the computer add and multiply the numbers stored in the variables A and B.

NEW
10 CLS
20 A=2
30 B=5
40 PRINT A+B
50 PRINT A*B
RUN

Answers displayed on their own are not very useful. If you add these PRINT lines to the program, you can make the computer display the sum next to the answer.

35 PRINT A;"+";B;"=";
45 PRINT A;"x";B;"=";

First LIST your program and notice that because we used line numbers 35 and 45, those new lines were inserted into the program you've already entered.

Now RUN your program.

Notice that you can also use a ; at the end of a line to tell the computer not to start a new line with the next PRINT command.

Cake program

Four monsters have been given 12 cakes and they want to share them out equally. The program below will solve the monsters problem. The variable C contains the number of cakes. M is the number of monsters and A is the answer.

NEW
10 CLS
20 C=12
30 M=4
40 A=C/M
50 PRINT "THERE ARE ";A;" CAKES"
60 PRINT "FOR EACH MONSTER"
RUN

Run the program to find out how many cakes each monster will get.