How to return the median value of 3 float values using if statements in Ada
27 November 2022 at 18:42
My assignment is to create a subprogram that takes in 3 float values in returns the median of those 3 float values as an integer using if statements. Iยดve tried a couple of ways to write this if statement but it just gives me a random value back of those 3 values I put in. My code:
function Median(Fl1, Fl2, Fl3: in Float) return Integer is
begin
if Fl3 >= Fl1 then
if Fl1 >= Fl2 then
return Integer(Fl1);
else
return Integer(Fl2);
end if;
elsif Fl1 >= Fl3 then
if Fl3 >= Fl2 then
return Integer(Fl3);
else
return Integer(Fl2);
end if;
elsif Fl2 >= Fl3 then
if Fl3 >= Fl1 then
return Integer(Fl3);
else
return Integer(Fl1);
end if;
end if;
end Median;
How can I rewrite this to work?