Question 2: (back)

Modify program (1), above, to draw lines between the columns and rows. Use the hyphen ('-'), vertical bar ('|'), and plus sign ('+') characters to draw the lines. E.g.,

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 Question2;

#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 Question2;
    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, " | " );
        add( 1, c );
    endwhile;

    mov( a, al );
    mov( al, c );
    mov( b, al );
    stdout.newln();
    stdout.put( "-----+" );
    while( c <= al ) do
        stdout.put( "----+" );
        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, "   | " );
        
        mov( a, bl );
        mov( bl, d );
        
        while( cnt2 <= al ) do
            mov( d, bl );
            add( c, bl );
            mov( bl, e );
            stdout.put( e, " | " );
            add( 1, d );
            //stdout.put( cnt2 );
            add( 1, cnt2 );
        endwhile;
        
        mov( a, bl );
        mov( bl, cnt2 );
        mov( b, bh );
        stdout.newln();
        stdout.put( "-----+" );
        while( cnt2 <= bh ) do
            stdout.put( "----+" );
            add( 1, cnt2 );
        endwhile;
        
        add( 1, c );
        add( 1, cnt );
        mov( a, bl );
        mov( bl, cnt2 );
    endwhile;

end Question2;