/* 
   September 11, 2005
   Charlie Peck
   
   Solution to Exercise 4, Programming Project 10, from Chapter 2 of Savitch, 
   with extra credit.
*/ 
#include <iostream>
#include <string> 
using namespace std;
#include <cmath>

int main() {
	int positive_sum = 0, negative_sum = 0;
	int positive_count = 0, negative_count = 0; 
	int i;
	// xxx hidden dependency, populate labels[] below if you increase how_many
	const int how_many = 10; 
	string labels[how_many] = {"first", "second", "third", "fourth", "fifth",
	  "sixth", "seventh", "eigth", "ninth", "tenth (and last)"}; 
	int tmp; 

	cout.setf(ios::fixed); 
	cout.setf(ios::showpoint); 
	cout.precision(2); 
	
	cout << "This program will prompt you for 10 integers, positive or " << 
	  "negative, \nat the end it will display statistics about the " << 
	  "numbers.\n\n"; 
	
	for (i = 0; i < how_many; i++) {
		cout << "Enter the " << labels[i] << " number: "; 
		cin >> tmp; 
		if (tmp > 0) {
			positive_sum += tmp; 
			positive_count++; 
		} else {
			negative_sum += tmp; 
			negative_count++; 
		}
	}

	cout << "\nSum of the numbers > 0 is " << positive_sum << "\n"; 
	cout << "Average of the numbers > 0 is " << 
	  static_cast<double>(positive_sum) / static_cast<double>(positive_count) <<
	  "\n\n"; 

	cout << "Sum of the numbers <= 0 is " << negative_sum << "\n"; 
	cout << "Average of the numbers <= 0 is " << 
	  static_cast<double>(negative_sum) / static_cast<double>(negative_count) <<
	  "\n\n"; 

	cout << "Sum of all the numbers is " << negative_sum + positive_sum << "\n"; 
	cout << "Average of all the numbers is " << 
	  static_cast<double>(positive_sum + negative_sum) / 
	  static_cast<double>(positive_count + negative_count) << "\n"; 

	return(0); 
}





/* 
bubba$ ./4_pp-c2-10 
This program will prompt you for 10 integers, positive or negative, 
at the end it will display statistics about the numbers.

Enter the first number: 44
Enter the second number: 1
Enter the third number: -4
Enter the fourth number: 5
Enter the fifth number: 1092838
Enter the sixth number: 19
Enter the seventh number: -756352
Enter the eigth number: 988
Enter the ninth number: 128
Enter the tenth (and last) number: -765

Sum of the numbers > 0 is 1094023
Average of the numbers > 0 is 156289.00

Sum of the numbers <= 0 is -757121
Average of the numbers <= 0 is -252373.67

Sum of all the numbers is 336902
Average of all the numbers is 33690.20
*/ 