-- Program from Lecture 22 for Sieve of Eratosthenes<BR>
-- Quintin Cutts 8 - 11 - 96<BR>
<BR>
with Ada.Text_IO; use Ada.Text_IO;<BR>
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;<BR>
<BR>
procedure l9 is<BR>
<space>    package Float_IO is new Float_IO( Float ) ;<BR>
    use Float_IO ;<BR>
    <BR>
    Amount, Balance : Float := 0.0 ;<BR>
    Trans_Type      : Character ;<BR>
    Ok_Trans        : Boolean ;<BR>
begin<BR>
    while not End_Of_File loop<BR>
        -- Read in type of transaction and amount involved<BR>
        Get( Trans_Type ) ;<BR>
        Get( Amount ) ;<BR>
        <BR>
        -- Set flag indicating whether we're interested in this transaction<BR>
        Ok_Trans := true ;<BR>
        <BR>
        -- Perform appropriate action according to transaction type<BR>
        if Trans_Type = 'd' then<BR>
            Balance := Balance + Amount ;<BR>
            Put( "deposit    " ) ;<BR>
        elsif Trans_Type = 'w' then<BR>
            Balance := Balance - Amount ;<BR>
            Put( "withdrawal " ) ;<BR>
        elsif Trans_Type = 'i' then<BR>
            Balance := Balance + Amount ;<BR>
            Put( "interest   " ) ;<BR>
        elsif Trans_Type = 'c' then<BR>
            Balance := Balance - Amount ;<BR>
            Put( "charge     " ) ;<BR>
        else<BR>
            Put( "Bad t_type" ) ;<BR>
            Ok_Trans := false ;<BR>
        end if ;<BR>
        <BR>
        -- Write out account information<BR>
        if Ok_Trans then<BR>
            Put( Amount, Fore => 3, Aft => 2, Exp => 0 ) ;<BR>
            <BR>
            -- Is the balance positive or negative?<BR>
            if balance >= 0.0 then<BR>
                Put( Balance, Fore => 3, Aft => 2, Exp => 0 ) ;<BR>
            else<BR>
                Put( abs Balance, Fore => 3, Aft => 2, Exp => 0 ) ;<BR>
                Put( " o/d" ) ;<BR>
            end if ;<BR>
        end if ;<BR>
        <BR>
        -- Tidy up for next transaction<BR>
        Skip_Line ; New_Line ;<BR>
    end loop ;<BR>
end l9;<BR><BR>

