A programmer writes a program to weigh baskets of fruit in grams, keeping a total of the weight
and counting the number of baskets. The total weight is stored in a variable Total and the number
of baskets is stored in a variable BasketCount.
Explain, including examples of programming statements, how totalling and counting could be used
in this program.

The following pseudocode algorithm uses nested IF statements.
IF Response = 1
THEN
X X + Y
ELSE
IF Response = 2
THEN
X X – Y
ELSE
IF Response = 3
THEN
X X * Y
ELSE
IF Response = 4
THEN
X X / Y
ELSE
OUTPUT "No response"
ENDIF
ENDIF
ENDIF
ENDIF

a). Name the type of statement demonstrated by the use of IF … THEN … ELSE … ENDIF

b). Re-write the pseudocode algorithm using a CASE statement.


Shares:

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.