Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
DECLARE Mark1 : INTEGER
DECLARE Mark2 : INTEGER
DECLARE Mark3 : INTEGER
INPUT Mark1
INPUT Mark2
INPUT Mark3
OUTPUT ROUND((Mark1 + Mark2 + Mark3) / 3, 1)What is output for the marks 7, 8 and 8?
Bonus ← ROUND(RANDOM() * 10, 0) + 5. What are the smallest and the largest values Bonus can take?DIV is the whole part of a division and MOD the remainder. ROUND(Value, Places) rounds to a number of decimal places, and RANDOM() returns a number from 0 to 1. LENGTH(Text) counts the characters, SUBSTRING(Text, Start, Length) takes a piece starting at Start (position 1 is the first character), UCASE and LCASE change the case.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Part (a). The total is 23, and . To one decimal place that is 7.7.
Part (b). RANDOM() is from 0 to 1, so RANDOM() * 10 is from 0 to 10. Rounded, it is a whole number from 0 to 10. Adding 5 gives a value from 5 to 15.
Check. The two ends are reached only when RANDOM returns 0 or 1, or a value close enough to round to them, so 5 and 15 are possible.
Answer: (a) 7.7. (b) from 5 to 15.
Log in to join the discussion.
Loading…