Question 1: (back)
Write a program to produce an "addition table." This table should input two small int8 values from the user. It should verify that the input is correct (i.e., handle the ex.ConversionError and ex.ValueOutOfRange exceptions) and is positive. The second value must be greater than the first input value. The program will display a row of values between the lower and upper input values. It will also print a column of values between the two values specified. Finally, it will print a matrix of sums. The following is the expected output for the user inputs 15 & 18:
add 15 16 17 18 15 30 31 32 33 16 31 32 33 34 17 32 33 34 35 18 33 34 35 36
program Question1; #include( "stdlib.hhf" ); #include( "excepts.hhf" ); static a: int8; b: int8; c: int8; d: int8; e: int8; cnt: int8 := 0; cnt2: int8 := 0; GoodInteger: boolean; begin Question1; repeat mov( false, GoodInteger ); try stdout.put( "Please enter a integer: " ); stdin.geti8(); mov( true, GoodInteger ); 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( GoodInteger ); mov( al, a ); mov( al, c ); repeat mov( false, GoodInteger ); try stdout.put( "Please enter another integer: " ); stdin.geti8(); mov( true, GoodInteger ); 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; if ( al < a) then stdout.put( "Integer value is too low, please re-enter", nl ); mov( false, GoodInteger); endif; until( GoodInteger ); mov( al, b ); // Second Integer 'b' sub( a, al ); // Subtract First from Second Integer mov( al, d ); // Set subtracted answer to 'd' // Output the first row mov( b, al ); // set al = 'b' stdout.newln(); stdout.put( "add " ); while( c <= al ) do stdout.put( c:5 ); add( 1, c ); endwhile; // Output all other rows mov( a, al ); mov( al, c ); mov( al, cnt2 ); mov( d, ah ); // Set ah = 'd' mov( b, al ); while( cnt <= ah ) do stdout.newln(); stdout.put( c:-4 ); mov( a, bl ); mov( bl, d ); while( cnt2 <= al ) do mov( d, bl ); add( c, bl ); mov( bl, e ); stdout.put( e:5 ); add( 1, d ); //stdout.put( cnt2 ); add( 1, cnt2 ); endwhile; add( 1, c ); add( 1, cnt ); mov( a, bl ); mov( bl, cnt2); endwhile; end Question1;