#include <iostream>
#include <time.h>
using namespace std;

void main (void)
{
	// the next three lines declare the variables that this program	will use
	int count, i;
	float average,sum,value[20]; // value is an array variable which							  //can hold 20 floating point values
	char again;

	cout << "This program will calculate the sum and average of a list of numbers \n";
	cout << "the maximum number of values that can be generated is 20 \n";
	cout << "the list will end if a value of zero is generated \n";
	
	do	
	{
		average = 0;	// these 3 lines initialise the variables 
		count = 0;	// used to calculate the sum and average
		sum = 0;
		
		for (i = 0; i < 20; i++) // this loop places -1 in every 
			value[i] = -1;	     // element of the array
			
		srand ((unsigned) time(NULL));

		do	// this loop generates a list of values and calculates			
		{	// the sum of these values
			value[count] = rand()%100;
			sum = sum + value[count]; // this line sums the values entered
			if (value[count] != 0) count++;//this line keeps count of how many numbers have been entered
		}
		while ((count < 20) && (value[count] != 0)); //this line checks	for a full array or for a zero entry 
		average = sum/count;	// this line calculates the average of the numbers entered
		cout << "the following " << count << " numbers were generated \n";
		for (i=0; i <count; i++)// this loop displays the numbers generated
		{
			cout << "\nvalue [" << i+1 << "] = " << value[i];
		}
		cout << "\n\nThe sum of these numbers is " << sum;
		cout << "\nThe average of these numbers is " << average;

		cout << "\nDo you want to generate another list of numbers ? ";
		cin >> again;
	}
	while ((again == 'y') || (again == 'Y'));	// this line checks to see if the user wants another go
	cout << "\n\n	End of program	\n\n";
}
