TCEA State Programming Contest

April 28, 2001

Problem 2.5 MultiplicAverage

**General Statement:** For a collection of integers, multiply them together and then divide by the number of integers in the collection. Round the answer to 3 decimal places.

**Input:** The first line in the data set is an integer that represents the number of data collections that follow. There are an unknown number of integers in each dataset. The integer –1 is used to indicate the end of the collection of integers.

**Output:** Round the answer to 3 decimal places. Trailing zeros to the right of the decimal point are required. The output is to be formatted exactly like that for the sample output given below.

**Assumptions:** The integers are in the range 1..500. The –1 used to indicate the end of the data collection is not part of the data for the problem.

**Sample Input: **

3

6 8 7 2 9 -1

1 2 3 4 5 6 7 -1

11 8 13 -1

**Sample Output:**

AVERAGE = 1209.600

AVERAGE = 720.000

AVERAGE = 381.333

**Solutions:**

#include

#include

using namespace std;

int main ()

{

int dataSet;

cin >> dataSet;

while ( dataSet– ) {

double total = 1;

double input;

cin >> input;

int count = 0;

while ( input != -1 ) {

count++;

total *= input;

cin >> input;

}

cout << "AVERAGE = " << setprecision (3) << fixed << total/count << endl; } return 0; } [/sourcecode]

I wrote a program for this problem.