bobnino 0 Newbie Poster

vb code

Integer Array Calculations

problem concerns some simple array handling.

Problem specification
Given an array of integers, you have to perform some integer calculations, and display some information concerning their number, their sum and average values, their minimum and maximum values, and the number of even and odd integers.

Method

Create an empty integer array that will hold up to 20 integers of a maximum value of 150 (a number over this should end the program without displaying totals).

Then, repeatedly read integer values from the keyboard until the user types zero. Afterwards, loop through the array and display the number of integers read (excluding the terminating zero), their sum (an integer), their average (a double), the minimum and maximum values encountered (both integers), and finally the number of even and odd integers read (these should be declared as integers too).

Always exclude the terminating zero from your calculations.

Error conditions: If you encounter a negative number (e.g. -151), display the message “Negative number: -151”
Don't take it into account in your calculations.
If you encounter a number greater than 150 (e.g. 399), display the message “Value exceeds 150: 399” and exit immediately.

If there are no valid numbers in the array to process, display the message No numbers to process! and exit immediately.

Typical input: 31 10 20 50 88 77 40 66 0

Typical output: Numbers read: 8
Sum: 382
Average: 47.75
Minimum: 10
Maximum: 88
Even: 6
Odd: 2