# Tutorial: How to write games

Go to page << 1 2 3 4 5 6 7 8 9 10 11 >>

## Basic4GL as a calculator

Here's our second program.
Before typing it in, click the new program button on the toolbar , to tell Basic4GL we are working on a new and different program.

 ```print "4 + 5 = " print 4 + 5```

Again, click on the "Go" button to run the program. So now we can use Basic4GL as a calculator!
Infact we've just written our first expression!

You've just written your first expression: 4 + 5
And the computer has calculated the result and displayed it (with print).

Again let's break it down.
This program has two instructions. Each on a different line.

print "4 + 5 = "
This is just like the Hello World program. We have used the print command, and supplied it with the text "4 + 5 = " as a quoted string. We know that this means write the text "4 + 5 =" to the screen.

print 4 + 5
This looks much like the first line, except the 4 + 5 is not a quoted string anymore. We are using the print command again, but this time using 4 + 5 as the parameter.
So what does the computer do? It evaluates
4 + 5 first. It calculates that 4 + 5 equals 9, and then sends 9 through to print as the parameter.
So the second line prints out a 9 on the screen.

Try modifying the program to calculate other equations. Here are some examples:

 4 + 5 + 6 7 * 8 * means multiplication 14.2 - .5 3 / 2 / means division 1 + 2 * 3 (1 + 2) * 3 sqrt (2) (1 + sqrt (2)) * 2 "Cat" + "fish" "Five" + 5 "1" + "3" "4 x 5 = " + 4 * 5

Some notes to be aware of:

• Some arithmetic operations are performed before others. E.g. multiplication (*) is always performed before addition and subtraction (+)
• You can force the order of evaluation by using brackets
• sqrt is a function (calculates the square root).
You can use functions anywhere that you can use a regular number.
• You can use plus (+) to join two quoted strings together.
Go to page << 1 2 3 4 5 6 7 8 9 10 11 >>