Mathematical Operations in BASIC


BASIC requires that all numerical operations be inputted in a form that the computer can use. For Example, if a person were to write the simple operation of three times six on a sheet of paper, he might write it "3 � 6". (I know the period outside the quotation marks is grammatically incorrect, but it gets confusing in examples). In BASIC, the "�" cannot be used because of its alternate use as a algebraic variable. (If you're not familiar with algebra, God forbid, a variable is a letter that represents a number). To solve this problem, you must use the "*" symbol in place of the "�".

 *** Start Geek Alert ***

All mathematical operations inputted in BASIC are carried out by the math co-processor built into all i486 DX and greater processors (I Think).

*** End Geek Alert ***

 TERMS TO KNOW

 BASIC Expression - any combination of meaningful constants, symbols, and/or variables

BASIC Symbol - any meaningful symbol used to express a mathematical function or operation

Unary Operation - any use of the "+" or the "-" sign to express the positivity or the negativity of a number or variable.

 Right now, you're probably thinking, "Alright, we get the point, so how do I enter mathematical expressions so that the computer will understand them." Well, the "+" symbol is simply expressed using the '+' symbol. Ha, I had you fooled!!! You thought I was going to teach you some incredibly difficult way to express that operation!!! Anyway, the "-" symbol may be expressed likewise. As we mentioned before, the "�" symbol may be expressed using the "*" symbol. The famous "�" symbol must be expressed using the "/" symbol (A forward slash).

Any exponential operations must be expressed using the "^" symbol (the carrot). Now you're probably thinking, "How does a stupid "^" symbol represent a exponent!" Well, in normal exponents the Base would be the larger number on the left and the exponent would be the smaller super-script number on the right. Expressing this is just the same: The Base is on the left of the carrot and the exponent is on the right. So, two to the third power would be written 2^3.

Since there is no [./�] button on the keyboard nor would any BASIC translator be able to use it if there was, you must you must put all roots in exponential fractional form (e.g., square root of four would be expressed 4^(1/2) or 4^0.5) or use the SQR function [e.g., SQR(4)].

If you have ever worked with a calculator program on a computer you may have seen output similar to this: 3.7925925925926e16. This means that the number is too big to be calculated accurately by the computer and it's giving you an estimate. The "e16" means that you can relocate the decimal place 16 places to the right. The estimated number in this case would be 37925925926000000. Notice that the computer didn't give me any numbers past the 10th decimal place so, I placed zeros in the places not given. Oppositely, if you see one that ends in "e-3" then you would move your decimal place 3 places to the right to get the approximate value.

That concludes our first session. Our next session will feture extended coverage of the PRINT Statement. Expect it to be out sometime in the next two weeks. Have a good day.


Assignments

Create a program that asks for numerical input from the user, calculates the sum, and then displays the FULL equation (e.g., 2 + 4 = 6). Be sure to use good spacing to provide readablity.



Create a text-based basic function (+, -, *, /) calculator that accepts two numbers and a symbol.



Return to Table of Contents


Last Updated August 25, 2002 by Jared P. Sutton

Hosted by www.Geocities.ws

1