CSC 270 
Homework 2

Assigned Sept. 18, due Sept. 22


Write a C++ program that reads in an int, then that many double numbers into an array, prints their sum and average (appropriately labelled), and prints out how many of them are positive. The task of finding the sum should be done by a function named sum to which the array is passed. The task of counting how many are positive should be done by a function named countPos to which the array is passed. The int at the beginning should be no smaller than 0, nor larger than 100; if it is, your program should print an appropriate error message rather than asking for the doubles and printing the results.

For example, if the input were
5 3.7 5.2 -4.7 -62 14.7
the output might be
Sum: -43.1
Average: -8.62
3 of your 5 numbers are positive.

Also turn in sample runs with well-chosen test cases.


Last modified: 
Stephen Bloch / sbloch@adelphi.edu