CSM 157 PROGRAMMING-Week2
CSM 157 PROGRAMMING-Week2
• Input statements
• Output statements
• Looping/iterative/repetitive statements
• Variable name must start with either an English alphabet (a-z or A-Z) or the
underscore symbol (_). If more than one character is used, the rest of the
characters should be English alphabets, digits (0-9) or the underscore
symbol.
• Variable names must be Short and meaningful to make our programs easy
to read and understand.
• Note that some programing languages such as C++ are case sensitive
as such Pay, PAY and paY are different variable names. In this course,
we will assume case sensitivity.
∞
DECLARE variable , 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 𝐴𝑆 dataType
0
Where datatype is one of the following:
INTEGER for integer numbers
DOUBLE for real numbers
BOOL for Boolean (True/False)
CHAR for variables that store single characters
STRING for variables that stores more than one character.
Variables Declarations
• Variables that are of the same data type be declared using a single
DECLARE statement.
Examples
(i) To declare A, B and C as integers, this can be written as
DECLARE A, B, C AS INTEGER
(ii) To declare Sum as integer and Average as a real number we can have
DECLARE Sum AS INTEGER
DECLARE Average AS DOUBLE
Variables Initialisation
• In some programming languages, when a variable is declared and it is
used without being assigned an initial value, it would have an
unknown value that can lead to unpredictable outputs when used in
an expression especially if the variable appears to the right hand side
of the replacement sign.
• Initialise yourself any variable whose initial value is obtained from an
input statement or an assignment statement.
Effect of using Integers and Real numbers in an
expression
Operator Integer Real/Double
Integer Integer Real/Double
Real/Double Real/Double Real/Double
Examples
Evaluate each of the following expressions bearing in mind that table
above.
i. 37/38*38+5.0
ii. 37/38.0*38.0+5.0
iii. 37.0/38*38+5.0
iv. 37.0/38.0*38+5.0
v. 37/38*38+5