CPSC 120 LAB 8 to Lab index page

Lab must be completed and reviewed by Peer Instructor Seth Peery no later than Fri, Oct 19 during lab class.

You are to write a nicely documented Ada program that will utilize both a procedure and a function to implement some simple data input and calculations. The program should ask the user to input two float numbers between 0.0 and 10.0. The program will then pick the smaller of these two numbers and add it to a sum. This process will be repeated until the user enters either an out of range float or other invalid input. If the user enters invalid input, he/she should be told the input was invalid and then asked to input again. If the user enters F (for finished),  the program should stop requesting or getting input. Once there is no more input, the program should display the sum to that point. Your program will be built in three parts. First, you should build a procedure that implements the input portion of the requirement. The procedure must implement exception handling. If the person tries to enter invalid input, an exception will be raised. The user should be asked to repeat the input, unless the input = F.  If the input = F, the input should be finished and the program should display the sum and end.  Second, a function minimum should be implemented which returns the smaller of the two values given to it as parameters. An outline of the program follows, you'll have to complete the procedure and the function.

Procedure lab8 is

type smfloat is float range 0.0..10.0

procedure getinput (a:out smfloat; b:out smfloat; s:in out character);

end getinput;

function minimum(

end minimum;

-------------------------------------------------------------
-- here's the main program. it's short, concise, and elegant!

x,y:smfloat;
sum:float;
stop:character:='G';

Begin -- main program

loop

Getinput (x,y,stop);
exit when stop = 'F';
sum:= sum+minimum(x,y);

end loop;

Ada.Text_IO.Put(item=>"The sum of the smaller numbers is ");