C++ primer plus第六版课后编程练习答案:6.2

#define  _CRT_SECURE_NO_WARNINGS 
#include 
#include
#include
using namespace std;

int main()
{
    const int Artsize = 10;
    array<double,10>donation;
    double num;
    int i = 0;
    int bigger = 0;
    double sum = 0;

    if (!(cin >> num))
        return 0;
    while ((cin >> num)||i==10)
    {
        donation[i] = num;
        sum += donation[i];
        i++;
    }
    double average = sum / i;
    for (; i - 1 >= 0; i--)
    {
        if (donation[i - 1] > average)
            bigger++;
    }
    cout << "The average is " << average << " and there are " << bigger << " numbers is bigger than it!" << endl;
    return 0;
}

你可能感兴趣的:(C++,primer,plus第六版课后编程练习)