我是 Ada 编程语言新手,正在做练习,
说明如下,
• Write a case statement with 4 alternatives that displays information on a roll of a pair of dice.
– A winning roll (7 or 11)
– A losing roll (2 or 3 or 12)
– A point roll (4 or 5 or 6 or 8 or 9 or 10)
– An invalid roll (less than 2 or greater than 12)
• Use the others option for the point roll
– In reality, I’d use the others option for invalid rolls
– The expressions Integer’First and Integer’Last yield the smallest possible (most negative) integer and largest possible integer.
我可以想出以下代码,但不知道如何处理
An invalid roll
情况,
我尝试在线搜索,阅读 docs.adacore.com,但找不到任何可以帮助我理解的内容
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Learning is
Dice : Integer; -- the value of a roll
begin
Put_Line ("Enter the value of your roll of the dice");
Get (Dice);
New_Line;
Put("The number ");
Put(Item => Dice, Width => 0);
case Dice is
when 7 | 11 =>
Put_Line ("is a winning dice roll");
when 2 | 3 | 12 =>
Put_Line ("is a losing dice roll");
when TBD =>
Put_Line ("is not a valid dice roll");
when others =>
Put_Line ("establishes the point");
end case;
New_Line;
end Learning;
我正在使用 JDoodle 来编译我的程序。