Public feed #889371

Miscellany

public text v1 · immutable
Raw Edit
·published 2008-02-02 21:29 UTC
rendered paste body
with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;

procedure myprogram is

    -- My first little Ada program.

    c : character;      -- c is a char variable, 1 character long.
    s : string(1..20);  -- s is a string variable 20 characters long.
    len : natural;      -- len is a zero or positive integer variable.
    x : integer := 10;  -- x is a integer variable. Default value 10.

begin

    New_Line;
    Put_Line( "All this program does is output some text" );
    Put_Line( "and test a simple loop. Press enter to continue." );
    Get_Immediate( c );
    New_Line;
    
    Put_Line( "A simple while loop, counting down from 10 to 0:" );
    New_Line;
    
    while x >-1 loop
        Put( x );
        New_Line;
        x := x - 1;
    end loop;
    
    New_Line;
    Put_Line( "There! That was easy." );
    New_Line;
    
    Put_Line( "Try typing a single character and press enter:" );
    Get( c );   -- What the heck is going wrong here???
    New_Line;
    Put_Line( "You typed: " & c );
    New_Line;
    
    s := "                    "; -- set s to 20 spaces to avoid weird characters
    Put_Line( "Now, lets try typing a sentence, no longer than 20 characters:");
    Get_Line( s, len ); 
    
    New_Line;
    Put_Line( "You typed:" );
    Put_Line( s );
    New_Line;
    
    Put_Line( "Press enter to quit." );
    Get_Immediate( c );

end myprogram;