-- This program does some simple analysis of some numbers
-- read from standard input until end of file.
-- It finds the sum of all of the values, and it
-- counts the number of positive, zero, and negative values
-- It displays the sum and the counts.
--
--
-- Author: Ned Okie
-- Date: 9/7/2009
with ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;
procedure getgeninteofcountPZN is
Num_Ints: Natural := 0; -- Number of elements that are input
sum: Integer := 0; -- Sum of all values
-- Number of positives, zeros, and negatives that were input
numPositives, numZeros, numNegatives: Natural := 0;
aNum: Integer; -- Temporarily holds each input number
begin
-------------------------------
-- Uses a general loop
-------------------------------
-- Input and process some values
-- using an end of file loop
loop
put("Enter a number: ");
exit when ada.text_io.end_of_file;
get(aNum);
-- Count the number of integers that have been input
Num_Ints := Num_Ints + 1;
-- Sum the number
sum := sum + aNum;
-- Count Positives
if aNum > 0 then
numPositives := numPositives + 1;
-- Count Zeros
elsif aNum = 0 then
numZeros := numZeros + 1;
-- Count Negatives
else -- aNum < 0 must be true
numNegatives := numNegatives + 1;
end if;
end loop;
-- Print number, sum and counts
put_line("Overall count:" & Num_Ints'img);
put_line("Overall sum:" & sum'img);
put_line("Number of positives:" & numPositives'img);
put_line("Number of zeros:" & Natural'image(numZeros));
put_line("Number of Negatives:" & Integer'image(numNegatives));
end getgeninteofcountPZN;