2

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.

Dandy Pham
  • 31
  • 1
  • 2
  • Also consider [*Command line arguments for Ada*](http://stackoverflow.com/q/14491899/230513). – trashgod Feb 20 '17 at 05:36
  • That link look like it is dealing with the character string tho. Is Ada has any kind of getting the array input ? Thanks for help man. – Dandy Pham Feb 20 '17 at 06:30
  • Might the task be to put single numbers into the components of an array? Or, to that effect, to find a way of extracting single numbers from a string? – B98 Feb 20 '17 at 07:20
  • Have you read section A.10 in the language reference manual? It describes how `Ada.Text_IO` (and `Ada.Integer_Text_IO`) works in great detail? – Jacob Sparre Andersen Feb 20 '17 at 08:41
  • 1
    You might want to consider using a loop to read values and place them in your array. – Jim Rogers Feb 20 '17 at 16:57
  • 1
    To be explicit, the Ada standard library does not provide any way of reading from standard input or a file to fill an array of any kind of object (other than `Character`, of course, in the form of `String`s). You have to code the loop and (at its simplest, without e.g. any error checking) use `Ada.Integer_Text_IO.Get` for each element of `Data` in succession. – Simon Wright Feb 20 '17 at 21:42

1 Answers1

2

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;