Previous topic | Ada Home Page | Index

Example: I/O and Assignment


--------------------------------------------------------
-- Calculate medicare levy program
-- Written by: Lawrie.Brown@adfa.oz.au / 6 March 1995
--------------------------------------------------------

with TEXT_IO; use TEXT_IO;      -- specify packages

procedure medicare is
    -- declare integer and float I/O libraries
    package int_io is new TEXT_IO.INTEGER_IO( INTEGER );
    package float_io is new TEXT_IO.FLOAT_IO( FLOAT );
    use  int_io, float_io;

    -- declare any constants and variables required
    medicare_rate : constant float := 1.4; -- % rate
    initials : string(1..3);    -- users initials
    gross : float;              -- gross income
    deductions : float;         -- total deductions
    taxable : float;            -- taxable income
    levy : float;               -- amount of levy

begin -- medicare
    -- get gross income and deductions
    PUT ( "Please enter your initials (3 letters) ");
    GET ( initials ); SKIP_LINE;
    PUT ( "Please enter your gross income $");
    GET ( gross ); SKIP_LINE;
    PUT ( "Please enter your deductions   $");
    GET ( deductions ); SKIP_LINE;

    -- calculate total income & levy
    taxable := gross - deductions;
    levy := taxable * medicare_rate / 100.0;

    -- display the result
    NEW_LINE;
    PUT ( "Initials:       ");
    PUT ( initials ); NEW_LINE;
    PUT ( "Gross Income:   $");
    PUT (gross, fore=>1, aft=>2, exp=>0); NEW_LINE;
    PUT ( "Deductions:     $");
    PUT (deductions, fore=>1, aft=>2, exp=>0); NEW_LINE;
    PUT ( "Taxable Income: $");
    PUT (taxable, fore=>1, aft=>2, exp=>0); NEW_LINE;
    PUT ( "Medicare Levy:  $");
    PUT (levy, fore=>1, aft=>2, exp=>0); NEW_LINE;
end medicare;


Previous topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 12 Feb 96