-- string_IO.adb a sample to demonstrate input and output of -- string type data, and using the if-then-else structure -- -- The names of four transactions are defined as an Ada strings. -- i.e. a user chosen set of english words that can be input, -- output, and recognized. This is an alternative to enumeration types. -- Bank_Transactions can be OPEN CLOSE DEPOSIT WITHDRAW with Ada.Text_IO ; use Ada.Text_IO ; procedure String_IO is subtype Transactions is String ( 1 .. 8 ) ; Transaction : Transactions ; begin loop Put_Line ( " Enter transaction. " ) ; Get ( Transaction ) ; Put ( Transaction ) ; Put_Line ( " transaction being processed" ) ; if Transaction = "OPEN " then -- note filled in spaces PUT_Line ( " opening " ) ; elsif Transaction = "CLOSE " then -- a short string would have ASCII nul Put_Line ( " closing " ) ; elsif Transaction = "DEPOSIT " then Put_Line ( " depositing " ) ; elsif Transaction = "WITHDRAW" then -- this fills string, determines length Put_Line ( " withdrawing " ) ; else Put_Line ( " not a transaction " ) ; end if ; end loop ; -- make a string literal fit where it is to be stored, 1..8 Transaction := "THE_" & ( 5..Transactions'Last => ' ' ) ; Transaction := "THE_" & ( 1..4 => ' ' ) ; end String_IO ; -- Enter transaction. data printed as entered -- OPEN transaction being processed -- opening -- Enter transaction. -- DEPOSIT transaction being processed -- depositing -- Enter transaction. -- WITHDRAW transaction being processed -- withdrawing -- Enter transaction. -- CLOSE transaction being processed -- closing -- Enter transaction. -- open transaction being processed -- not a transaction -- Enter transaction. -- JUNK transaction being processed -- not a transaction -- Enter transaction. -- raised ADA.IO_EXCEPTIONS.END_ERROR