Dandy Pham
Dandy Pham

Reputation: 31

Ada How to get input a list of integer from a user and put it into an array

Im sorry to ask this question but Ada is really strict on an input and output system so I cant figure out how to get the input from a the user and put it into an array.

with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada;

procedure Main is
 type MY_ARRAY is array(1..9) of INTEGER;
   Data        : MY_ARRAY;

begin
   Put("Please input the series of numbers");
   Get_Line(Data);
end Main;

I know this is completely wrong but I research everywhere and I cant find how people get the input to an array LOL. Thank yall for help.

Upvotes: 2

Views: 7836

Answers (1)

Laura Gonzalez
Laura Gonzalez

Reputation: 21

I think it's easier to use only the package Ada.Text_IO so that you can read each number as a String and then store it as an integer one by one using a for loop and Integer'Value, which converts from String to Integer.

with Ada.Text_IO;
use Ada.Text_IO;

procedure Main is
    type MY_ARRAY is array(1..9) of Integer;
    Data : MY_ARRAY;

begin
    Put_Line("Please input the series of numbers");

    for I in 1..MY_ARRAY'Length loop
        Data(I) := Integer'Value(Get_Line);
    end loop;
end Main;

Upvotes: 2

Related Questions