You do not need an array.
Your assignment is pretty simple. Take a list of numbers and:
1) add them all together
2) multiply them all together
3) average them
To add a number with another, you need to keep a running sum.
sum = sum + x;
To multiply a number with another, you need to keep a running product.
product = product * x;
To find the average, you need the sum (which you calculate elsewhere) and the number of numbers you have.
count = count + 1;
Each time you read a new number, update your sum, product, and count. Once you have read all the numbers, you can calculate the average the normal way:
1 2 3 4 5
|
average = sum / (double)count;
cout << "Sum =" << sum << endl;
cout << "Product=" << product << endl;
cout << "Average=" << average << endl;
|
So, what should
sum,
product, and
count be before you read any numbers?
Hope this helps.