Computers are very good at math. Let's get the computer to do some math for us. Here's a simple multiplication calculator:
CLS INPUT "Enter the first number: ", A INPUT "Enter the second number: ", B PRINT "The answer is: "; A * B
If you have trouble finding the star (or asterisk "*") on the keyboard, it is usually above the number 8. Run it, and enter two numbers. It does an excellent job multiplying for you.
Variables and Math
A and B are variables, just like Name$. Unlike Name$, A and B do not have a dollar-sign after their names. This is because they are only holding numbers, not letters.
Star
"A * B" means "A times B". QBASIC doesn't use "X" for multiplication because you might want to have a variable called "X".
What else?
Try changing the "A * B" to "A - B" for subtraction. "A + B" will do addition, and "A / B" will do division. Why "/" for division? Because there's no division sign key on the keyboard. At least I haven't found one.
Expressions
"A * B", "A + B", "A - B", and "A / B" are called mathematical expressions, or simply "expressions".
Learned
- Variables with numbers
- INPUT with numbers
- Multiplication, Division, Addition, Subtraction
- Expressions
No comments:
Post a Comment