Previous topic | Ada Home Page | Index

GET_LINE example


-----------------------------------------------------------------------
-- Chris Lokan, April 1995
-- Compute average of three marks
-- Demonstrate string I/O
-----------------------------------------------------------------------

with TEXT_IO;
procedure TESTAVE is
 
    package FLT_IO is new TEXT_IO.FLOAT_IO(FLOAT);
    use  TEXT_IO, FLT_IO;
 
    NAME : STRING(1 .. 18);
    NAMELEN : INTEGER;
    SCORE1, SCORE2, SCORE3, TOTAL, AVE : FLOAT;
 
begin
    PUT("Enter name, or type end to stop: ");
    GET_LINE(NAME, NAMELEN);
 
    while NAME(1..NAMELEN) /= "end" loop
        PUT("Enter three test scores : ");
        GET(SCORE1);
        GET(SCORE2);
        GET(SCORE3);
        SKIP_LINE;
 
        TOTAL := SCORE1 + SCORE2 + SCORE3;
        AVE := TOTAL / 3.0;
 
        NEW_LINE;
        PUT("Student name  ");
        PUT_LINE(NAME(1..NAMELEN));
        PUT("Total   score ");
        PUT(TOTAL, EXP => 0, FORE => 3, AFT => 1);
        NEW_LINE;
        PUT("Average score ");
        PUT(AVE, EXP => 0, FORE => 3, AFT => 1);
        NEW_LINE;
 
        NEW_LINE;
        PUT("Enter name, or type end to stop: ");
        GET_LINE(NAME, NAMELEN);
    end loop;
end TESTAVE;


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