我是Ada的新手,目前正试图编写一个涉及if-else if语句的简单程序。代码如下:Ada字符串比较
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Year_Codes is
Year : String(1..9) := " ";
CharsRead : Natural;
function YearCode(Name : in String) return Integer is
begin
if(Name = "freshman")then
return 1;
elsif(Name = "sophomore")then
return 2;
elsif(Name = "junior")then
return 3;
elsif(Name = "senior")then
return 4;
else
return 0;
end if;
end YearCode;
begin
Put("Enter your academic year: "); -- Prompt for input
Get_Line(Year, CharsRead); -- Input
Put(YearCode(Year)); -- Convert and output
New_Line;
end Year_Codes;
我得到0为每个答案。关于我在做什么的任何输入都是错误的?
您的E-lisp程序应该在单独的问题中。我已经回答了你的Ada问题。该答案与您的E-lisp程序无关。 –
我想如果我问两个我会被大喊,但我会把它拿出来:对不起 – ola
我编辑了你的Ada代码来纠正缩进并添加'with'和'use'子句。我还冒着更新你的标题和标签的自由(真正的问题是字符串比较,而不是'if'语句)。 –