Equations are part of the process function of a program. Unlike what you were taught in math, in QBASIC, calculations can be made on both letters and numbers, but for this part, we'll concentrate on the numbers part.
Equations are facilitated with use of the LET statement. For instance:
LET answer=7+4
LET length=wdth/height
LET pickles=salami-mustard
The main equations are as follows:
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
^ | Exponentiation |
Operations go by the standard equation order.
What happens if you have two multiplications, or two additions in a row? Then you go left to right, just like you would read a sentence.
One little thing when working within QBASIC. Normally, in high school math, you were taught that (3*4)*(4*6)
and (3*4)(4*6)
were the same. Unfortunately, you can't use the shorthand demonstrated in the latter example. If you have (length*wdth*height)length
, for instance (I don't know why, but you might want to), you have to spell it out, as in (length*wdth*height)*length
You might wonder why I spelled width wdth. That's because, in QBASIC, WIDTH is what is known as a reserved word. Like LET and PRINT, WIDTH is a reserved word (the functions of which, I will explain later). You cannot name a variable WIDTH
. You can, however, name a variable with Width in it, provided that it is nested within a whole word. For instance, you could have one variable named WidthOfHouse.