I am confused about changing types in Ada. Specifically receiving user input, which is stored as a string, and then performing operations on it as a float or integer. My goal is to make a table of logarithms based on a users start and stop points, incrementing by any value they want. I have tried something such as: Start := Float'Image(Start); I could you some help, thanks.
with Ada.Text_IO, Ada.Float_Text_IO, Ada.Numerics.Elementary_Functions;
use Ada.Text_IO, Ada.Float_Text_IO, Ada.Numerics.Elementary_Functions;
procedure log_table is
Start, Stop, Increment, temp : Float;
begin -- Prompt for input
Put_Line("To print a table of logarithms,");
Put(" enter the start, stop, and increment values: ");
Get(Start); Get(Stop); Get(Increment);
loop
exit when (Start > Stop);
Put("The logarithm of");
Put(Start);
Put(" is ");
Put_Line( log(Start, 10.0) );
Start := Start + Increment;
end loop;
end log_table;
So the code now runs... I will post the changed portion of code below. All I did was change the Put_Line function to a Put function and then added a New_Line function after. Any reason why this works? From my understanding the only difference between Put_Line and Put is that is adds a '\n' to the end. A better understanding would be appreciated.
loop
exit when (Start > Stop);
Put("The logarithm of ");
Put(Start);
Put(" is ");
Put( log(Start, 10.0));
New_Line;
Start := Start + Increment;
end loop;
use
clause, and insert the full names of the subprograms you call, you might also learn a bit. – Jacob Sparre Andersen