Homework Issues

You need to test your programs

You need to check the compile error messages and fix them.

If you put an if statement in your program you have to:

  • Test the case where the condition is true
  • Test the case where the condition is false
  • Test the case where the condition changes from true to false

Write code that easier to test

Compute the product, display the product, then convert the currency.

 Else if

Put the negative product test first in the else if’s.

e.g.

If (product<0) then
   Msgbox(error)
 Elseif
   Do this
 Elseif
   Do that
 endif

Error messages – error messages should refer to the field which generated the error.

Factoring

If you have this:

If (cond) then
 Do a
 Do c
else
 Do b
 Do c
End if

It’s the same as this:

If (cond) then
 Do a
Else
 Do b
End if
Do c

The second way is generally better because it takes less lines and is easier to understand. Only put in conditionals things that you do conditionally.