Selection Exercise 1
Develop a program to read an examination mark. It should display a Pass if the mark lies between 40% - 60% (inclusive), Merit if it lies above 60% and Fail if it lies below 40%
Algorithm
ExamMarks
read exam mark
if exam mark > 60 then
write Merit
else
if exam mark >= 40 then
write
Pass
else {exam
mark must be less than 40%}
write
Fail
endif
endif
End.
Because the evaluation of a nested if statement produces mutually exclusive selection the above nested if statement will work. If the mark is not > 60 then the program will evaluate the mark for >= 40. This will result in the evaluation of marks between 40 and 60 inclusive as any mark > 60 would have been picked up at the start of the if statement.
Data
Item Table
Data Item | Program name | Size/Type | Range |
Exam mark | mark | integer |
PROGRAM: marks.cpp