DISPLAYING THE VALUE OR CONTENTS OF
VARIABLES
The write or writeln statement displays the value
of variables on the console screen. To print text, enclose inside
single quotes. To display the value of a variable, do NOT enclose
using single quotes, eg, the following program displays the
content of each of the variables declared.
program DISPLAYVARIABLES (output); var number1 : integer; letter : char; money : real; begin number1 := 23; letter := 'W'; money := 23.73; writeln('number1 = ', number1 ); writeln('letter = ', letter ); writeln('money = ', money ) end.
The display output from the above program will be,
number1 = 23 letter = W money = 2.3730000000E+01
SELF
TEST 4
Each of the following expressions is wrong. Rewrite each using
correct Pascal, in the space provided.
Firstletter := A; ___________________________________ StartCount:= Initial := 0; ___________________________________ Taxrate := 5%; ___________________________________ Total := 5 plus 7; ___________________________________ Effeciency := .35; ___________________________________ Click here for answer
SELF
TEST 5
What is displayed by the following program.
program EXERCISE1 (output); var a, b : integer; c : real; begin a := 1; b := 5; c := 1.20; writeln('A = ', a + 3 ); writeln('B = ', b - 2 ); writeln('C = ', c / 2 ) end. Click here for answer
PROGRAM
ONE
You are to write a program which calculates and prints on the
screen, the time required to travel 3000 miles at a speed of 500
mph.
PROGRAM TWO
Write a program to calculate the gross pay for a worker named
FRED given that FRED worked 40 hours at $2.90 per hour.