5.2.2 Algorithms Worksheet 2 Operators Student
5.2.2 Algorithms Worksheet 2 Operators Student
Worksheet 2 –Operators
Questions
a. Let a = 4
Let b = 10
result = (a * b) / 2
output result
b. Let a = true
Let b = false
output a||b
c. Let y = true
Let x = true
result = x&&y
Output !result
d. Let Age = 18
Output (Age < 18)
a. Input Age
Input Name
NameOK = (Name == “Freda”)
AgeOK = (Age ===18)
AllDataOK = AgeOK && NAMEOK
Output AllDataOK
b. Input Age
Input Name
NameOK = (Name == “Freda”)
AgeOK = (Age ===18)
AllDataOK = AgeOK !! NAMEOK
3. Assuming a quadratic equation has the form ax 2 + bx + c = 0 write down the algorithm to ask the user for the
values of a, b and c and the output the two values of x.
Hint: You should use the quadratic formula
4. A computer is connected to three switches that can be on or off and one bulb that can be on or off.
It can read the state of each of the switches into variables, e.g:
var1 = switch1
It can turn the bulb on or off using a line of code, e.g.
Bulb = TRUE
Bulb = var1
5. What is the statement needed to complete the algorithm below for a simple vending machine? Add ‘Yes’
and ‘labels’ as necessary.