Question 4: (back)
Write a program that reads a list of positive numbers from a user until that user enters a negative or zero value. Display the sum of those positive integers.
program Question4;
#include( "stdlib.hhf" );
static
a: int32;
b: int32 := 0;
Done: boolean := false;
begin Question4;
repeat
mov( false, Done );
try
stdout.put( "Please Enter a Number: " );
stdin.get( a );
mov( a, eax );
if( eax = 0 ) then
mov( true, Done );
elseif( eax <= -1 ) then
mov( true, Done );
else
add( eax, b );
endif;
exception( ex.ConversionError );
stdout.put( "Illegal numeric value, please re-enter", nl );
exception( ex.ValueOutOfRange );
stdout.put( "Value is out of range, please re-enter", nl );
endtry;
until( Done );
stdout.put( "The total of entered integers are: ", b, nl );
end Question4;