mardi 16 février 2016

Which of these is the correct if statement?

In the following pseudocode, what percentage raise will an employee in Department 3 receive?

if department < 2 then
 raise = SMALL_RAISE
endif
if department < 6 then
raise = MEDIUM_RAISE
endif
if department < 10
raise = BIG_RAISE
endif

A: SMALL_RAISE

B: MEDIUM_RAISE

C: BIG_RAISE

D: Impossible to tell

I chose medium raise because department < 6 is the first true statement within that block. Well according to my teacher, its big raise. Why is it big raise? edit:

EDIT: Then why is this example medium raise? big raise is still the last true test.

In the following pseudocode, what percentage raise will an employee in Department 8 receive?

if department < 5 then
raise = SMALL_RAISE
else
if department < 14 then
  raise = MEDIUM_RAISE
   else
  if department < 9
     raise = BIG_RAISE
  endif
 endif
endif  

Aucun commentaire:

Enregistrer un commentaire