CALL connect_to_grocer
IF connect_OK
THEN CALL send_credit_card_number
INPUT shopping_item
DOWHILE shopping_item <> 'END'
CALL transmit(shopping_item)
INPUT shopping_item
END DOWHILE
CALL disconnect_link
ELSE DISPLAY 'Connection not available'
ENDIF
The dial-in shopping list algorithm has room for improvement. What problems does it have? Rewrite the algorithm to overcome the problems.
The major problem is that we dial-in to the grocer's computer and send a credit card number before testing the shopping list to make sure that it isn't empty. The loop priming, apart from not sending an empty shopping list, can also guard against an unecessary phone call.
INPUT shopping_item
IF shopping <> 'END'
THEN
CALL connect_to_grocer
IF connect_OK
THEN CALL send_credit_card_number
DOWHILE shopping_item <> 'END'
CALL transmit(shopping_item)
INPUT shopping_item
END DOWHILE
CALL disconnect_link
ELSE DISPLAY 'Connection not available'
ENDIF
ELSE DISPLAY 'Empty shopping list, call to grocer cancelled'
ENDIF
This publication is copyright David Beech and Learning Systems 1997-2002
and may not be reproduced by any means without the written permission of
David Beech.
9 Wyndella Street, Tasmania, Australia