with Ada.Text_Io;
-- all statements in
with Ada.Integer_Text_Io; -- enables the reading and writing of
integers
procedure Inclassdemo3 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
loop
begin
Ada.Text_Io.Put
(
" Please
enter a move for the user, it may be rock, paper or
scissors ");
Move_Io.Get
(User_Move);
exit when (user_move = paper or user_move = scissors or
user_move = rock);
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 ");
end; -- as long as user
makes errors will remain in the loop w.o. bombing
end loop;
Ada.Text_Io.Put (
" Please enter a move for the computer, only
rock, paper or scissors ");
begin
Move_io.get (Computer_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 (Computer_Move); -- this still bombs on 2nd error
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
-- example of an attribute of enumerated type
move_Io.Put
(item =>I, width => 20);
end loop;
end Inclassdemo3;