【发布时间】:2016-01-29 15:38:41
【问题描述】:
我刚开始学习 Ada 95,但在比较字符串时遇到了一些问题。
代码如下:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Command_Line;
with Ada.Strings.Unbounded;
procedure Test1 is
vad : String(1..9);
Amount : Integer;
Main : Integer;
Second : Integer;
Third : Integer;
begin
Main := 1;
Second := 0;
Third := 0;
Put("What do you want to do?");
New_Line(1);
Get(vad);
New_Line(1);
if Vad = "fibonacci" then
Put("How long do you want the sequence to be");
New_Line(1);
Get(Amount);
New_Line(1);
Amount := Amount -1;
for I in 1 .. Amount loop
Put(Main);
New_Line(1);
--Put(" ");
Third := Second;
Second := Main;
Main := (Second + third);
end loop;
New_Line(2);
elsif Vad = "two" then
Put("How long do you want the sequence to be?");
New_Line(1);
Get(Amount);
New_Line(1);
for U in 1 .. Amount loop
Put(U * 2);
Put(", ");
end loop;
else
Put("ok");
end if;
end Test1;
就像现在一样,当我输入fibonacci 时,if 语句会识别,但当我输入two 时,它只会转到代码的“else”部分。
有什么想法可能是错的吗?
提前致谢。
【问题讨论】:
标签: string if-statement compare ada