4.1.1 How it works
An expression combines values with operators to compute another value. The basic arithmetic operators are addition +, subtraction - and multiplication *, plus the minus sign in front of a number.
The type of the result depends on the operands:
| Operands | Result |
|---|---|
Integer and Integer | exact Integer |
at least one Real | Real |
At the top, Integer plus Integer gives Integer. Below, Integer times Real gives Real.
ProgramThe basic sums
Algorithm Aritmetica
Define precio As Integer <- 7;
Define cantidad As Integer <- 3;
Write precio + cantidad, " ", precio - cantidad, " ", precio * cantidad;
Write precio * 1.5, " ", -precio;
EndAlgorithmOutput
10 4 21 10.5 -7
The program finishes normally.
Arithmetic operators only accept numbers. Adding a number and a boolean, or a number and a text, is detected before running.
In short
+,-and*operate on numbers.- Two integers give an exact integer; if there is a real, the result is real.
- Going outside the integer range stops the program.