The intent of a program is usually to model some aspect of the real world
A data object (variable) which the program manipulates thus represents some object in the real world. The data type should best reflect the properties of the object.
In Ada, a variable has a
Main predeclared data types in Ada:
INTEGER FLOAT CHARACTER STRING BOOLEAN
(There is also a type called FIXED, for real numbers. We will stick to FLOAT for real numbers.)
Constants are data values that do not change
answer : constant STRING := "forty two"; medicare_rate : constant FLOAT := 1.4; pi : constant FLOAT := 3.1415926536;
Form:
Benefits:
english_drink := metric_drink * 0.568; litres_to_pints : constant float := 0.568; english_drink := metric_drink * litres_to_pints;
Ada has strong typing - you cannot mix data types
3 + 4 ok 3.0 / 4.0 ok 1.0 > 0 error 3 * 4.0 error
mixed arithmetic - must convert one type to another
1.0 > FLOAT(0) ok FLOAT(3) * 4.0 ok 3 * INTEGER(4.0) ok
FLOAT (integer value)
INTEGER (float value)
An example program demonstrates type coercion, among other things.