// ************************************************************
//  Jeff Balsley  10/15/2001
//  
//
//  Assignment: Write a program that asks for three integers 
//  from the user and then displays the integers, the sum of 
//  the integers, and the product of the integers. The sum and 
//  product of the integers are to be calculated in separate 
//  functions which are called from main().
// *************************************************************
//  Known Bugs: 
//
// *************************************************************

#include <iostream>
using namespace std;
#include <cmath>

const int SIZE = 3; // number of numbers to be inputted

int sum(double num[]);
int product(double num[]);

int main()
{
	double num[SIZE];
	int i;

	cout << "This program will take 3 integers as input,\n"; 
	cout << "and return their sum and product.\n";

	for (i=0; i<SIZE; ++i){
		do{
			cout << "Enter integer #" << i+1 << "> ";
			cin >> num[i];
			// If the input is not an integer, get new user input
			if ( floor(num[0]) != ceil(num[0]) ){
				cout << "*** Please enter an INTEGER! ***\n";
			}
		} while ( floor(num[0]) != ceil(num[0]) );
	}
	// *************** //
	// print output    //
	// *************** //

	cout << "-----------------------------\n";
	cout << "Your numbers are " << num[0];
	cout << ", " << num[1] << ", " << num[2] << "\n";
	cout << "The sum of these numbers is " << sum(num) << "\n";
	cout << "The product of these numbers is " << product(num) << "\n";

	return 0;
}

// *********************************************************************
//  This fuction takes an array of doubles as the input and returns
//  the sum of those numbers
// *********************************************************************
int sum(double num[])
{
	int i;
	int sum = 0;
	for (i=0; i < SIZE; ++i){
		sum = (int)sum + (int)num[i];
	}
	return (sum); 
}

// *********************************************************************
//  This functions takes an array of doubles and returns their sum
// *********************************************************************
int product(double num[])
{
	int i;
	int product = 1;
	for(i=0; i<SIZE; ++i){
		product = product * (int)num[i];
	}
	return(product);
}