所以我为 Ada 创建了一个猜谜游戏,但是它没有运行。错误出现在第 25 行。 它说 guessing_game.adb:25:26:错误:没有候选解释与实际相符:
with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Numerics.Discrete_Random;
procedure Guessing_Game is
type Number_Range is range 1 .. 100;
package Random_Number is new Ada.Numerics.Discrete_Random(Number_Range);
use Random_Number;
Generator : Random_Number.Generator;
Secret_Number : Number_Range;
Guess : Number_Range;
Attempts : Integer := 0;
Last_Guess : Integer := -1;
begin
Reset(Generator);
Secret_Number := Random(Generator);
Ada.Text_IO.Put_Line("1 to 100, if not guessed then byebye system32!");
loop
Ada.Text_IO.Put("guess NOW:");
Ada.Integer_Text_IO.Get(Guess);
if Integer(Guess) = Last_Guess then
Ada.Text_IO.Put_Line("Try one more before the os is deleted!");
else
Attempts := Attempts + 1;
Last_Guess := Integer(Guess);
if Guess < Secret_Number then
Ada.Text_IO.Put_Line("eeeee too smol");
elsif Guess > Secret_Number then
Ada.Text_IO.Put_Line("eeeee too big");
else
Ada.Text_IO.Put_Line("Ok you guessed it in ");
Ada.Integer_Text_IO.Put(Attempts);
Ada.Text_IO.Put_Line(" attempts, os wont be removed anymore");
exit;
end if;
end if;
end loop;
end Guessing_Game;
我已经尝试将其更改为直接通过猜测来获取,但它不起作用。
您已将名为
Guess
的变量指定为 Number_Range
类型,其定义如下:
type Number_Range is range 1 .. 100;
在第 24 行,您尝试使用通用包
Get
的实例来 Guess
用户的
Integer_IO
,该实例使用标准类型 Integer
实例化,允许 here。
一种方法是将
Number_Range
定义为具有所需范围的 Integer
的 子类型:
subtype Number_Range is Positive range 1 .. 100;