【发布时间】:2021-11-17 22:27:08
【问题描述】:
任务很简单,但由于以下情况,我无法解决它:
创建一个procedure类型的子程序,用户可以在其中输入两个整数 键盘。整数必须传递给主程序。 然后主程序应该打印这些数字。
例如:
输入两个整数:83 122
这两个整数是:83 122
这是我的方法:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Hello is
procedure Two_Integers (Integer_1, Integer_2 : out Integer) is
Integer_1, Integer_2 : Integer;
begin
Put("Type two integers: ");
Get(Integer_1);
Get(Integer_2);
end Two_Integers;
begin
Put("The two integers were: ");
Two_Integers(Integer_1, Integer_2);
Skip_Line;
end Hello;
我收到以下错误代码:
Integer_1 conflicts with declaration at line 6
Integer_2 conflicts with declaration at line 6
Integer_1 is undefined
Integer_2 is undefined
我在想我的子程序有两个本地声明的整数变量,然后它会发送 OUT“整数”。然后在我的主程序中调用这个子程序并按照说明输入整数。
我该如何解决这个问题?非常感谢您的帮助!
【问题讨论】:
-
您需要在主过程中定义两个整数作为您的过程 Two_Integers 的实际参数。 Integer_1 和 Integer_2 都没有定义在过程 Hello 的范围内。
-
@leun,一个快速的礼仪说明:你最近问了很多问题,这很好!你已经得到了一些很好的答案。接受您认为已充分回答您的问题的任何答案是一种很好的礼仪。
-
尝试使用
-gnatl进行编译 - 它会打印出您的程序并显示错误消息。 -
这些错误的信息是:了解声明使事物可见的位置,也就是范围规则。
标签: ada