ExamBank Scot · N5 Computing Science question bank · All N5 Computing Science questions
10 marks · Input validation
When the two numbers are entered the program should ensure that numTwo is always a higher number than numOne. Using pseudocode or a programming language of your choice, write several lines to represent this input validation for line 2. When the pupil enters the answer it is stored in a variable called “guess”. State the data type stored by the variable “guess”. The program is run with the following data. Variables Values numOne 7 numTwo 15 randNum 10 guess m State the output from the program. The program will have to make use of a pre-defined function. State the pre-defined function used and describe its purpose. Using line numbers, describe how the code could be adapted, allowing the pupil to play the game 10 times using the same values for numOne and numTwo but a different random number each time. A Maths game is designed for primary school pupils to test number ordering. In the game the pupil is asked to enter two integer numbers. A third integer number is then randomly generated and shown to the pupil. The pupil must then state if the random number is: lower (l) than the two entered numbers higher (h) than the two entered numbers in the middle (m) of the two entered numbers. A design for the code is shown below. Line 1 <enter the first number and assign to numOne> Line 2 <enter the second number and assign to numTwo> Line 3 <generate random number and assign to randNum> Line 4 SEND randNum TO DISPLAY Line 5 RECEIVE guess FROM (CHARACTER) KEYBOARD Line 6 IF guess = “l” AND randNum < numOne THEN Line 7 SEND “Correct it is lower” TO DISPLAY Line 8 SET score TO score + 1 Line 9 END IF Line 10 IF guess = “m” AND randNum >= numOne AND randNum <= numTwo Line 11 SEND “Correct it is in the middle” TO DISPLAY Line 12 SET score TO score + 1 Line 13 END IF Line 14 IF guess = “h” AND randNum > numTwo Line 15 SEND “Correct it is higher” TO DISPLAY Line 16 SET score TO score + 1 Line 17 END IF Line 18 <display incorrect message>
Design or code should include the following bullet points for 1 mark each: • loop • loop condition • user input, numTwo re-entered after condition (or within loop..until) • error message to user Do not accept any condition as the condition must be correct in context of candidates answer. For example: If candidate uses a conditional loop the condition should be either: loop until - numTwo > numOne while loop - numTwo <= numOne) If candidate does not use a loop but uses an IF statement check then mark the IF condition. Check the condition carefully. Character (char) Accept ‘string’ as you can store a string of 1 character. Output would be: “Correct it is in the middle” Accept line 11. One mark for each: • Random (Number) • To generate a random value between two values OR • between a range OR • between limits A correct description of the wrong pre-defined function should be awarded 1 mark. Accept program syntax for a random function such as: Randomint Rand Rnd Randnum RandInt Also accept Int or Round as the random number generated may be converted into an integer. One mark for function, one for description. Lines 3 to 17 (or 3 to 18) should be placed inside a loop (1 mark) Repeat 10 times (1 mark) Accept candidate implying lines to be repeated, for example - “loop/repeat everything after line 2”.