-- my version of contest.adb WITH ada.integer_text_io; WITH ada.text_io; PROCEDURE contest IS TYPE programmer IS ARRAY (1..10) OF integer; aProgrammer : programmer; number : integer; -- index of aProgrammer array lines_of_code : natural; -- produced by programmers each day max_position: natural; -- position of winning programmer sum : natural; -- total lines of code produced last: natural; -- programmer whose lines of code make sum >= 1000 done : Boolean; -- used so that last can't be reset BEGIN aProgrammer := (OTHERS => 0); -- output heading ada.text_io.put_line (" PROGRAMMER PROGRESS "); ada.text_io.put_line ("Programmer Lines of Code "); LOOP -- to pick up the data and echo it ada.integer_text_io.get (number); ada.integer_text_io.get (lines_of_code); ada.integer_text_io.put (number); ada.integer_text_io.put (lines_of_code); -- update the current programmer's total lines of code aProgrammer(number) := aProgrammer(number) + lines_of_code; -- test to see if current programmer's total is over 1000 IF (aProgrammer(number) > 1000) THEN -- output message and exit loop ada.text_io.put (" #"); ada.integer_text_io.put (number, width=> 0); ada.text_io.put_line (" goes over 1000. "); max_position := number; EXIT; END IF; ada.text_io.new_line; END LOOP; ada.text_io.new_line; -- output heading ada.text_io.put_line (" FINAL TOTALS "); ada.text_io.put_line ("Programmer Lines of Code "); -- print out the final totals while summing total lines of code done := false; sum := 0; -- sum will hold total lines of code of programmers -- up to but not including the winner. FOR i IN 1..10 LOOP -- ada.integer_text_io.put (i); ada.integer_text_io.put (aProgrammer(i)); sum := sum + aProgrammer(i); IF (i = max_position) THEN ada.text_io.put (" *** THE WINNER *** " ); END IF; ada.text_io.new_line; IF (sum >= 1000) and not done THEN last := i; -- index where total lines of code goes over 1000 done := true; -- so last won't be reset END IF; END LOOP; ada.text_io.new_line; -- print out the message ada.text_io.put (" It took programmers 1 through "); ada.integer_text_io.put (last); ada.text_io.put (" to produce more than the winner "); END contest;