-- shows use of data_error exception handler

with Ada.Text_Io;

with Ada.IO_Exceptions;

-- all statements in Ada end with a semi-colon (i.e. semi-colon is a terminator)

 

procedure Inclassdemo2 is      -- procedure body header

   -- declarations go here

   type Move is (Scissors, Paper, Rock);

 

   package Move_Io is new Ada.Text_Io.Enumeration_Io (Move);

 

   Computer_Move : Move; 

   User_Move     : Move; 

 

 begin

   Ada.Text_Io.Put (

      " Please enter a move for the user, it may be rock, paper or scissors ");

   begin

      Move_Io.Get (User_Move);

      Exception

        when others =>

           Ada.text_io.put_line (" you did not enter an appropriate value ");

           Ada.text_io.put (" Please enter:  rock,  paper or scissors ");

           Move_io.get (User_Move);

   end; 

 

   Ada.Text_Io.Put (

   " Please enter a move for the computer, only rock, paper or scissors ");

   begin

     Move_io.get (Computer_move);

     exception

       when Ada.IO_Exceptions.data_error =>

         Ada.text_io.put_line (" you did not enter an appropriate value ");

         Ada.text_io.put (" Please enter:  rock,  paper or scissors ");

         Move_io.get (Computer_Move);

 

       when others => -- others catches any defined exception not handled by

                      -- previous when statement

         Ada.text_io.put_line (" you did not enter an appropriate value ");

         Ada.text_io.put (" Please enter:  rock,  paper or scissors ");

         Move_io.get (Computer_Move);

    end;   

  

   Ada.Text_Io.Put ( " Here is what the user entered ");

   Move_Io.Put (User_Move);

   Ada.Text_Io.New_Line (1);

   Ada.Text_Io.Put (" here is what the computer's move is ");

   Move_Io.Put (Computer_Move);

   ada.text_io.new_line(1);

     

   for I in move'range loop

      move_Io.Put (item =>I, width => 20);

   end loop;

end Inclassdemo2;