Professional Documents
Culture Documents
07 If THEN Selection
07 If THEN Selection
Problem;
Input a mark from a test and grade it into Pass, 50 - 100 or Fail, less than 50.
Step 1.
Define the problem.
Step 2.
Outline the solution.
a) Processing Steps;
? Marks between 50 - 100 = Pass
? Marks less than 50 = Fail
b) Subtasks;
None
c) Control Structure;
Selection
IF-THEN-ELSE
d) Variables;
Marks
e) Mainline Logic;
Take the mark input by the user. Determine the range that it falls into and then show the result.
Step 3.
Solution Algorithm
BEGIN
BEGIN
READ mark READ
IF mark >= 50 THEN mark
DISPLAY “Pass
ELSE
DISPLAY “Fail mark DISPLAY
Yes
END IF >= 50 Pass
END ?
No
DISPLAY
Fail
END
Step 4
Deskcheck the Algorithm
First choose the test data.
Lets choose marks that will give obvious results, 75 and 25, plus some at the limits 50, 49, and 50.5
mark 75 25 50 49 50.5
Now setup a table of the relevant variable names and pass each test data set through the solution
algorithm, statement by statement.
Step 5.
Programming Code
LOGO
To Grade :mark
IFELSE :mark > 50
[PRINT "Pass]
[PRINT "Fail]
END
Note: There is a error in the above program. Find it and correct it.
QUICK BASIC
'Grade
CLS
INPUT "Mark"; mark
IF mark >= 50 THEN
PRINT "Pass
ELSE
PRINT "Fail
END IF
END
PASCAL
program Grade(input, output);
var
mark : integer;
begin
writeln('Enter a mark');
readln(mark);
if (mark >= 50) then begin
write('Pass');
end
else begin
write('Fail');
end;
end.
Step 6.
Test the program
Use as many inputs as possible. Especially test
those inputs which are close to the boundaries of
the decisions to be made by the program.