ada Outputting numbers Print Multiple Items On One Line

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Combine the instances of the _IO packages, use the right one with its numeric type.

with Ada.Text_IO;   use Ada.Text_IO;

procedure Print_Inventory is
    type Fruit is (Banana, Orange, Pear);
    subtype Count is Integer range -1_000_000 .. 1_000_000;

    package Fruit_IO is new Enumeration_IO (Fruit);
    package Count_IO is new Integer_IO (Count);

    Inventory : constant array (Fruit) of Count :=
      (Banana => 27_420,
       Orange => 140_600,
       Pear   => -10_000);

begin
    Fruit_IO.Default_Width := 12;

    for F in Inventory'Range loop
        Fruit_IO.Put (F);
        Put          (" | ");
        Count_IO.Put (Inventory (F));
        New_Line;
    end loop;
end Print_Inventory;

Result

BANANA       |    27420
ORANGE       |   140600
PEAR         |   -10000


Got any ada Question?