Storing arithmetic values
Quick reference
To store the value of an arithmetic expression in a variable, type:
variable = expression
To copy a real value into a data variable, type:
var_name(start,end) :dp = expression
dp is the number of decimal places required.
More information
In many of your Quantum programs, you will need to save the result of some arithmetic expression in a variable. The variable can be a column or an integer or real variable and the arithmetic information can be the contents of a column, integer or real variable, an integer or real number, or the results of the functions numb or random. It can also include arithmetic expressions which have been manipulated using the arithmetic operators +, -, / and *. Here are some examples to start with:
var1=100
/* Next statement expects that variable ntim is < 10
c135=ntim
/* In next example, if c31'5678', variable np=4
np=numb(c31)
/* Increment rect (record total) by 1 for each record processed
rect=rect+1
Copying a number into an integer or real variable is easy because the variable has no predetermined size; that is, Quantum does not say that such variables can only store numbers of up to, say, three digits. Integer variables can store any whole number in the range +2,147,483,648 to ‑2,147,483,647 and real variables can take values of any magnitude with six digits accuracy.
Suppose a questionnaire shows how many pints of milk a respondent bought and you want to save this is in an integer variable called npt. You might write:
npt=c(125,126)
Similarly, if you know how many miles the respondent travels to work each day, and convert this to kilometers, you could save the conversion in a real variable called km0:
km=c(213,214) * 1.609
If the respondent travels 5 miles, km will have the value 8.045, but if they travels 9 miles, km would be 14.481.
The main difference between the two examples is the type of variable in which the results are saved. The number of pints bought will always be a whole number so it is saved in an integer variable, whereas the conversion from miles to kilometers is likely to produce a real number so it is saved in a real variable.
See
See also