Vtech PreComputer Power Pad Plus User Manual - Page 40
Numeric Variables
View all Vtech PreComputer Power Pad Plus manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 40 highlights
Type this: 10 PRINT 3+11/7 RUN press ENTER Is it really evaluated from left to right? Yes, but was it the answer you were expecting? If the answer came out to 4.57143, the computer first divided 11 by 7 getting 1.57143 and then it added 3 to the result giving 4.57143. You probably were expecting the answer to be 2 because 3+11 is 14, then divided by 7 is 2. You can see that expressions are not simply evaluated from left to right. It is necessary to have an exact set of rules to follow. Here they are: Functions ( ) things in parentheses ^ raising to a power * / multiplication and division + - addition and subtraction Order in which they are performed (1st) (2nd) (3rd) (4th) The computer will always look at an expression in parentheses first and follows those commands. It could be an expression or more sets of brackets. Among the expression, raising to a power is calculated first, followed by multiplication and division from left to right, followed by addition and subtraction from left to right. If you're not sure how the computer will evaluate the expression, simply put brackets around the expression you want computed first. Remember the brackets must always be in pairs, one right bracket for each left one. If you don't use both brackets, you will receive a "? SYNTAX ERROR" message. NUMERIC VARIABLES You have seen how you can use BASIC to print numbers and messages. You can also give values to a BASIC program yourself. The computer uses a letter to stand for a value. This is called a variable. For example LET D = 609. This statement puts the value 609 into a memory box called "D." Try this. Type: 10 LET A=8 press ENTER 36