Reputation: 21
I am working on a project in ada that simply makes a list. However, when I try to add the variable to the list it says it is expecting a string for some reason. Here is my code:
with Ada.Text_IO; use Ada.Text_IO;
procedure hw6 is
type i is range 0..99;
type list is array (Integer range 0..99) of Integer;
nums : list(0..99);
procedure makeArray is
num: Integer;
begin
Print_Line("Enter stuff");
for index in 0..nums'Length loop
num := Integer'Value(Ada.Text_IO.Get_Line);
if num < 0 then
exit;
else
nums(index) := Integer'Value(num);
end if;
end loop;
end makeArray;
begin
makeArray;
end hw6;
I get an error that says
hw6.adb:17:54: expected type "Standard.String"
hw6.adb:17:54: found type "Standard.Integer".
Any help is appreciated.
Upvotes: 1
Views: 636
Reputation: 11
In line 13 you convert the input string into an integer value. In line 17 you try to do that a second time; but this time you apply the string-to-int conversion to an integer value. This cannot work. Omit the second convertion altogether and write
nums(index) := num;
That is what you intended to do.
The GNAT compiler produces additional error messages: Line 6: "array type is already constrained", To remove this, write
nums : list;
Line 11: Print_Line should be Put_Line.
Upvotes: 1