RSS | Roulette Scripter Studio | Lesson 4 | Arithmetic Statements and Operators | ||||||||||||||||||||||||||||||||

This tutorial was made by Silver | ||||||||||||||||||||||||||||||||

http://www.money-maker-machine.com/forum/profile/Silver/ | ||||||||||||||||||||||||||||||||

4. Arithmetic Statements and Operators. | ||||||||||||||||||||||||||||||||

I. Once you have declared a variable, stored values in it (lesson 2) - next step is perform calculations. The arithmetic operators in RSS are:
notes: - div and mod - only work on integers. - / - works on both reals and integers but will always yield a real answer. - the other operations work on both reals and integers. - when mixing integers and reals, the result will always be a real since data loss would result otherwise. - the value of x div y is the value of x/y rounded in the direction of zero to the nearest integer. - the mod operator returns the remainder obtained by dividing its operands. In other words, x mod y = x – (x div y) * y - a runtime error occurs when y is zero in an expression of the form x/y, x div y, or x mod y. II. Examples: a) Addition Example var number1, number2, result : integer; begin number1 := 10; number2 := 20; result := number1 + number2; print(number1); print('plus'); print(number2); print('is'); print(result); end; b) Subtraction Example var number1, number2, result : integer; begin number1 := 15; number2 := 2; result := number1 - number2; print(number1); print('minus'); print(number2); print('is'); print(result); end; c) Multiplication Example var number1, number2, result : integer; begin number1 := 5; number2 := 7; result := number1 * number2; print(number1); print('multiplied by'); print(number2); print('is'); print(result); end; d) Division Example var number1, number2, result : integer; begin number1 := 21; number2 := 4; result := number1 / number2; print(number1); print('divided by'); print(number2); print('is'); print(result); end; e) Integer division Example var number1, number2, result : integer; begin number1 := 21; number2 := 4; result := number1 div number2; print(number1); print('integer divided by'); print(number2); print('is'); print(result); end; f) Modulus(remainder division) Example var number1, number2, result : integer; begin number1 := 21; number2 := 4; result := number1 mod number2; print(number1); print('remainder division by'); print(number2); print('is'); print(result); end; III. Pay attention In RSS, the minus sign can be used to make a value negative. Do not attempt to use two operators side by side, like in: number := 37.5 * -2; This may make perfect sense to you, since you're trying to multiply by negative -2. However, RSS will be confused — it won't know whether to multiply or subtract. You can avoid this by using parentheses to clarify: number := 37.5 * (-2); The computer follows an order of operations similar to the one that you follow when you do arithmetic. Multiplication and division (* / div mod) come before addition and subtraction (+ -), and parentheses always take precedence. So, for example, the value of: 3.5*(2+3) will be 17.5. |
||||||||||||||||||||||||||||||||

Copyright © 2007-2011, All rights reserved to Money Maker Machine |