ITPEC FE Subject B April 2026 Question 2

From the answer group below, select the correct combination of answers to be inserted into A through C in the description.

Function f receives an integer value as argument argval and returns the grade character. The return value of f(92), f(72), and f(-10) are “A,” “B,” and “C,” respectively. Note that the function has a specification bug.

[Program]
○ character: f(integer: argval)
character: retvar ← "w"
if (argval > 90)
retvar ← "a"
endif
if (argval > 70)
retvar ← "b"
elseif (argval > 60)
retvar ← "c"
elseif (argval ≤ 60)
retvar ← "d"
endif
return retvar

Answer group

OptionABC

Explanation

A: b, B: b, C: d — the first if is a separate statement, so for 92 the second if overwrites the "a" it assigned.

That is the specification bug: every value above 90 is also above 70, so "a" can never survive.

  • •f(92) — retvar starts as "w"; 92 > 90 sets "a"; the second if then finds 92 > 70 and overwrites it with "b"
  • •f(72) — 72 > 90 is false; 72 > 70 sets "b"
  • •f(-10) — every > test fails, and the last branch, −10 ≤ 60, sets "d"

Answer (d)

Why not others:

  • •(a), (b) and (c) — give "a" for f(92), as if the two if statements formed one chain; the second if still runs and overwrites it
  • •(e) and (f) — give "c" for f(72), but 72 > 70 matches first and elseif stops the chain before the > 60 test
  • •(c) and (f) — also give "w" for f(-10), missing that the final elseif (argval ≤ 60) is true for −10, so the default is replaced

Key rule: Consecutive if statements are tested independently and a later match overwrites an earlier one; only elseif makes branches exclusive.

Math & Numbers · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.